Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 变量';将以下代码放入scope.js中的一个函数中,使输出为a:1、b:8、c:6_Javascript - Fatal编程技术网

Javascript 变量';将以下代码放入scope.js中的一个函数中,使输出为a:1、b:8、c:6

Javascript 变量';将以下代码放入scope.js中的一个函数中,使输出为a:1、b:8、c:6,javascript,Javascript,使用您对变量范围的了解,并放置以下代码 在scope.js中的一个函数内,因此输出为a:1、b:8、c:6 var a = 1, b = 2, c = 3; (function firstFunction(){ var b = 5, c = 6; (function secondFunction(){ var b = 8; (function thirdFunction(){ va

使用您对变量范围的了解,并放置以下代码
在scope.js中的一个函数内,因此输出为a:1、b:8、c:6

 var a = 1, b = 2, c = 3;  

 (function firstFunction(){  
     var b = 5, c = 6;  

     (function secondFunction(){  
         var b = 8;  

         (function thirdFunction(){  
             var a = 7, c = 9;  

             (function fourthFunction(){  
                 var a = 1, c = 8;  

             })();  
         })();  
     })();  
 })();  

我错过了一个问题我可以把console.log()放在哪里;为了能得到和他们要求我的一样的结果,我们来看看堆栈溢出。请阅读有关如何获得良好回复的建议。这看起来像是一个学生编程练习,你刚刚试着让我们为你做,所以不是那样的。你需要表明你自己已经做了一些努力来解决它,并且表明你认为问题与“提升”无关。变量声明和初始值设定项是每个函数中的第一个语句,没有任何地方可以“提升”它们。无论如何,赋值是在声明之后完成的,它关系到变量的可用性,而不是它们的值。是的,我的错。我同意这个定义的错误用法。我也这么做了,但没有跑步,非常感谢。我想我可能是打错了
 console.log("a: "+a+", b: "+b+", c: "+c);  
var a = 1, b = 2, c = 3;

(function firstFunction(){
 var b = 5, c = 6;  
 (function secondFunction(){  
     var b = 8;  
     console.log("a: "+a+", b: "+b+", c: "+c); //a: 1, b: 8, c: 6
     (function thirdFunction(){  
         var a = 7, c = 9;  

         (function fourthFunction(){  
             var a = 1, c = 8;  

         })();  
     })();  
 })();  
})();  
var a = 1, b = 2, c = 3; 
(function firstFunction(){  
         var b = 5, c = 6;  

         (function secondFunction(){  
             var b = 8;  

             (function thirdFunction(){  
                 var a = 7, c = 9;  

                 (function fourthFunction(){  
                     var a = 1, c = 8;  

                 })();  
             })(); 
    console.log("a: "+a+", b: "+b+", c: "+c);  // it's here because of 'hoisting'. if you need more I can explain
         })();  
     })();