mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-02-24 11:03:36 -05:00
1.8 KiB
1.8 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--
النمط الشائع في جافا سكريبت هو تنفيذ الـ function بمجرد إعلانه:
(function () {
console.log("Chirp, chirp!");
})();
هذا اسمه anonymous function expression الذي ينفذ على الفور، ويخرج Chirp, chirp! على الفور.
لاحظ أن ال function ليس له اسم وليس مخزن في متغير. ويؤدي القوسان () الواردان في نهاية ال function expression إلى تنفيذه أو استدعاءه على الفور. هذا النمط يعرف بـ immediately invoked function expression او IIFE.
--instructions--
أعد كتابة الدالة makeNest وأزيل استدعائها بحيث أنها تصبح anonymous immediately invoked function expression (IIFE).
--hints--
وينبغي أن يكون ال function مجهول اي anonymous.
assert(/\((function|\(\))(=>|\(\)){?/.test(code.replace(/\s/g, '')));
يجب أن يكون ال function الخاص بك بين قوسين في نهاية التعبير لاستدعائه على الفور.
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")
)();