AI

Understanding scope is key to mastering variables. var is function-scoped (or global), while let and const are block-scoped (only exist inside {}).

Your Task:

  • Inside the if block:
    • Create a variable blockScoped using let and set it to "I am safe"
    • Create a variable leakyVar using var and set it to "I leak out"
  • Outside the block (after the closing }):
    • Assign leakyVar to a variable capturedLeak (it should still exist!)
    • Try to assign blockScoped to capturedBlock (it would error, so just set capturedBlock to "Error caught" string for this exercise)
TypeScript Solution
Loading...

Submit your code to see test results