0

var z = 1; 

if (function f() {}) {    z += typeof f; } 

console.log(z);    

my expection was 1function

I thought the typeof f return "function"

but when i run this is chrome browser i get the output as 1undefined. I am not clear how typeof f invoked the function call

Jagan
  • 11
  • 1
  • 3
    The `function f() {}` positioned in the `if` clause is a function *expression* it is not a function available outside the scope. Same as if you had a `const g = function f() {}` - the `f` still won't be a valid identifier (although `g` would). A more apt comparison would be `(function f() {})` which is a function expression which just does nothing. – VLAZ Aug 23 '23 at 09:54

0 Answers0