Examples with typeof :

var y = 1;
  if (function f(){}) {
    y += typeof f;
  }
  console.log(y);

In the above example, the output is 1undefined as the if statement code executes at runtime, 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);

output : 1undefined

The if condition evaluates this statement using eval and the eval(function foo(){}) returns true. But as the statement executes at runtime the output will be 1undefined.

var k = 1;
  if (1) {
    function foo(){};
    k += typeof foo;
  }
  console.log(k);

Here, the typeof returns function and the output is :

1function

No comments:

Post a Comment

Overview of AngularJS

AngularJS is an open source web application framework. It is now maintained by Google . The most of the code can be eliminated by using th...