1.8 KiB
1.8 KiB
id | title | localeTitle | challengeType |
---|---|---|---|
587d7db2367417b2b2512b8b | Understand the Immediately Invoked Function Expression (IIFE) | Comprender la expresión de función invocada inmediatamente (IIFE) | 1 |
Description
(function () {Tenga en cuenta que la función no tiene nombre y no está almacenada en una variable. Los dos paréntesis () al final de la expresión de la función hacen que se ejecute o se invoque inmediatamente. Este patrón se conoce como una
console.log("Chirp, chirp!");
})(); // this is an anonymous function expression that executes right away
// Outputs "Chirp, chirp!" immediately
immediately invoked function expression
o IIFE
.
Instructions
makeNest
y elimine su llamada, por lo que es una immediately invoked function expression
forma anónima ( IIFE
).
Tests
tests:
- text: La función debe ser anónima.
testString: 'assert(/\(\s*?function\s*?\(\s*?\)\s*?{/.test(code), "The function should be anonymous.");'
- text: Su función debe tener paréntesis al final de la expresión para llamarla inmediatamente.
testString: 'assert(/}\s*?\)\s*?\(\s*?\)/.test(code), "Your function should have parentheses at the end of the expression to call it immediately.");'
Challenge Seed
function makeNest() {
console.log("A cozy nest is ready");
}
makeNest();
Solution
(function () {
console.log("A cozy nest is ready");
})();