Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

Is a named function expression's name available outside?

Do you know what will be the output of this code?

JavaScript
const f = function g() {
  return typeof g;
};

console.log(f(), typeof g);
Show answer and explanation

The answer is function undefined.

g is bound only inside the function body, which is useful for recursion. Outside, only f exists.

Take the full quiz Next question →

More Scope & Hoisting questions

  1. How do closures create private variables in JavaScript?
  2. How do you write a once() function with a closure?
  3. Can you call a function before it is declared in JavaScript?
  4. Why can't you call a function expression before it's defined?
  5. Can you change this on a bound function with call()?

Related topics