0

What is the output of this immediately invoked function expression (IIFE), and why does it behave that way?

author
subina kallyani
hard
1
66
console.log((function f() { return typeof f; })());
Answer

The output will be: "function"

  • The function is a named function expression with the name f.
  • Inside its own body, the function name f refers to itself, regardless of how the function was invoked.
  • Therefore, typeof f returns "function".

Important Detail:
This name f is not available outside the function.
Example:

console.log(typeof f); // ReferenceError: f is not defined


Click to Reveal Answer

Tap anywhere to see the solution

Revealed

Comments0
    What is the output of this immediately invoked function expression (IIFE), and why does it behave that way? - functions | EBAT