Question #16

Author: admin
tags: JavaScript  
const f = function coolFunction() {
  console.log('Hello from coolFunction!');
  if (!coolFunction.wasInvoked) { setTimeout(coolFunction, 500); }
  coolFunction.wasInvoked = true;
}

coolFunction();
How many times will the message 'Hello from coolFunction!' be output to the console?
1
2
3
There will be an error
The message will not be displayed.
The ReferenceError error will appear, because here not a simple functional expression is used, but a named functional expression in which the function name is visible only inside the function itself.
A variable with this name is not created outside the function.
By the way, you can still get this name outside the function: you need to use name property.
In this case, console.log(f.name); will write 'coolFunction'.
Rate the difficulty of the question:
easyhard