1.

What Will Be The Output Of The Code Below?  // Nfe (named Function Expression  var Foo = Function Bar() { return 12; };  typeof Bar();

Answer»

The output would be Reference Error. To make the code above WORK, you can re-write it as FOLLOWS:

Sample 1

 var bar = function()
{
return 12;
};
 typeof bar();



or

Sample 2

 function bar()
{
return 12;
};
 typeof bar();



A function definition can have only one reference variable as its function NAME. In sample 1, bar's reference variable points to anonymous function. In sample 2, the function's definition is the name function.

 var foo = function bar()

// foo is VISIBLE here 
// bar is visible here
console.log(typeof bar()); // Work here :)
 };
 // foo is visible here
 // bar is undefined here






The output would be Reference Error. To make the code above work, you can re-write it as follows:

Sample 1

 var bar = function()
{
return 12;
};
 typeof bar();



or

Sample 2

 function bar()
{
return 12;
};
 typeof bar();



A function definition can have only one reference variable as its function name. In sample 1, bar's reference variable points to anonymous function. In sample 2, the function's definition is the name function.

 var foo = function bar()

// foo is visible here 
// bar is visible here
console.log(typeof bar()); // Work here :)
 };
 // foo is visible here
 // bar is undefined here








Discussion

No Comment Found