1.

What Will Be The Output Of The Code Below? var Y = 1; if (function F(){}) { y += Typeof F; } console.log(y);

Answer»

The output would be 1undefined. The if CONDITION statement evaluates USING EVAL, so eval(function f(){}) returns function f(){} (which is true). Therefore, inside the if statement, executing typeof f returns undefined because the if statement code executes at RUN time, and the statement inside the if condition is evaluated during run time.

 var k = 1;
if (1)
{
eval(function foo(){});
k += typeof foo;
}
console.log(k); 
The code above will also output 1undefined.
 var k = 1;
if (1)
{
function foo(){};
k += typeof foo;
}
console.log(k); // output 1function





The output would be 1undefined. The if condition statement evaluates using eval, so eval(function f(){}) returns function f(){} (which is true). Therefore, inside the if statement, executing typeof f returns undefined because the if statement code executes at run time, and the statement inside the if condition is evaluated during run time.

 var k = 1;
if (1)
{
eval(function foo(){});
k += typeof foo;
}
console.log(k); 
The code above will also output 1undefined.
 var k = 1;
if (1)
{
function foo(){};
k += typeof foo;
}
console.log(k); // output 1function







Discussion

No Comment Found