JavaScript IIFE — exercises and bug fixes
5 hands-on exercises and 5 find-the-bug challenges for the JavaScript IIFE lesson. Every one is checked automatically in the browser — write the code, run it, and the tests tell you what still fails.
Exercises(5)
- 1
Write an IIFE
easy10 minUse an IIFE to work out 6 times 7 and store the answer.
- 2
Pass an argument
easy10 minPass the name Ada into an IIFE and return a greeting.
- 3
Keep a variable private
easy10 minShow that a variable inside an IIFE cannot be seen outside.
- 4
Return an object
easy10 minReturn a config object from an IIFE and show its version.
- 5
An arrow IIFE
medium10 minWrite the same idea as an arrow IIFE returning the word ready.
Find the bug(5)
- 1
Fix the IIFE that never runs
easy8 minWithout the final brackets the function is stored, not called.
- 2
Fix the argument in the wrong brackets
easy8 minThe argument belongs in the calling brackets.
- 3
Fix the leaked variable
easy8 minThe variable is declared outside, so it is not private.
- 4
Fix the missing return
easy8 minThe IIFE builds the object but never gives it back.
- 5
Fix the arrow IIFE syntax
easy8 minThe arrow function is never invoked.
Ready to write the code?
The editor, the automatic checks and the worked solutions open up with an account.
Open the workspace