Understand the Immediately Invoked Function Expression (IIFE)

Tell us what’s happening:
The below code is failing with error “the function should be anonymous”.

However, it runs perfectly well in node.js and is, I believe, a valid use of the new ES6 arrow function.

Your code so far


(  () => {
  console.log("A cozy nest is ready");
})();


Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-immediately-invoked-function-expression-iife

Tell us what’s happening:

Directions: Rewrite the function makeNest and remove its call so instead it’s an anonymous immediately invoked function expression ( IIFE ).

Quesiton: Can you provide me with some hints in order to solve the exericise? But first, how do I remove the function’s call?

Your code so far


(function () {
  console.log("A cozy nest is ready");
})(); // this is an anonymous function expression that executes right away?

makeNest(); 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.67 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/understand-the-immediately-invoked-function-expression-iife

Just delete the call of makeNest(); (i.e. just delete makeNest(); )

Edit: Otherwise your code is correct.

1 Like

(: Thank you kindly fellow camper.

Tell us what’s happening:
I don’t know why my code is not accepted!
can anyone help?
It’s console logging the same as described but why this code not considered as valid.
I am so curious to know. Waiting for replies…

Your code so far


(() => {
 console.log("A cozy nest is ready");
})();

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36.

The issue seems the same as the OP

1 Like