Scope, hoisting and closures
Explain lexical scope and closures from the spec model and use them deliberately.
- JS.02.01Lexical scope and the scope chainCoreJunior9 min
- JS.02.02Hoisting and the temporal dead zoneCoreJunior9 min
- JS.02.03Closures: functions that rememberCoreJunior10 min
- JS.02.04Closures and memoryCoreMid-level10 min
- JS.02.05Strict mode and the global objectCoreJunior8 min
Interview questions in this module
- What is a closure? Give a practical use.
- What will
for (var i=0;i<3;i++) setTimeout(()=>console.log(i))print? How do you fix it? - What is hoisting? Are
letandconsthoisted? - What is the temporal dead zone?
- What is lexical scope vs dynamic scope?
- How can closures cause memory leaks?
- What does strict mode change?
- Implement a function that can be called only once.