Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

1.6 KiB

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7db2367417b2b2512b8b Understand the Immediately Invoked Function Expression (IIFE) 1 301328 understand-the-immediately-invoked-function-expression-iife

--description--

A common pattern in JavaScript is to execute a function as soon as it is declared:

(function () {
  console.log("Chirp, chirp!");
})(); // this is an anonymous function expression that executes right away
// Outputs "Chirp, chirp!" immediately

Note that the function has no name and is not stored in a variable. The two parentheses () at the end of the function expression cause it to be immediately executed or invoked. This pattern is known as an immediately invoked function expression or IIFE.

--instructions--

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

--hints--

The function should be anonymous.

assert(/\((function|\(\))(=>|\(\)){?/.test(code.replace(/\s/g, '')));

Your function should have parentheses at the end of the expression to call it immediately.

assert(/\(.*(\)\(|\}\(\))\)/.test(code.replace(/[\s;]/g, '')));

--seed--

--seed-contents--

function makeNest() {
  console.log("A cozy nest is ready");
}

makeNest();

--solutions--

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

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

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

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