Reading — step 1 of 5
Learn
~1 min readScope and Closures
let and const are block-scoped — they only exist inside the { ... } they're declared in. var is function-scoped — it leaks out of blocks. That's why modern JS avoids var.
js
Hoisting: function declarations and var are 'hoisted' — JS knows about them at the top of their scope, so you can reference them before the declaration line. let and const are NOT hoisted (technically they are, but accessing before declaration throws — the temporal dead zone).
js
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…