Engrain by ByteRush

JS.02 5 concepts · 5 ready

Scope, hoisting and closures

Explain lexical scope and closures from the spec model and use them deliberately.

  1. JS.02.01Lexical scope and the scope chainCoreJunior9 min
  2. JS.02.02Hoisting and the temporal dead zoneCoreJunior9 min
  3. JS.02.03Closures: functions that rememberCoreJunior10 min
  4. JS.02.04Closures and memoryCoreMid-level10 min
  5. JS.02.05Strict mode and the global objectCoreJunior8 min

Interview questions in this module

  1. What is a closure? Give a practical use.
  2. What will for (var i=0;i<3;i++) setTimeout(()=>console.log(i)) print? How do you fix it?
  3. What is hoisting? Are let and const hoisted?
  4. What is the temporal dead zone?
  5. What is lexical scope vs dynamic scope?
  6. How can closures cause memory leaks?
  7. What does strict mode change?
  8. Implement a function that can be called only once.