while we're busting popular JS myths... "let doesn't hoist". False. var x = 2; { console.log(x); let x = 3; } That code throws a TDZ error because the `x` in `let x` was in fact hoisted to the { } scope; it's just uninitialized. If no hoisting, would print `2`.
-
Show this thread
-
Replying to @getify
Just to be clear. Hoisting rules are different for var and let?
1 reply 0 retweets 2 likes -
Replying to @aashishnagpal10
no they are not. they both hoist identically. var initializes, let does not. that's the difference.
5 replies 0 retweets 40 likes -
Replying to @getify @aashishnagpal10
Fine, I’ll bite. `var` and `let` do NOT hoist identically. `var` is function-scoped, `let` is block-scoped.pic.twitter.com/mn809oHVHH
2 replies 1 retweet 24 likes -
Replying to @mathias @aashishnagpal10
sigh. when I said "identically" I was talking about their behavior of attaching an identifier to start of a scope, not that they pick the same scope to attach to. I obvs know they bind to diff scopes. The point of the thread is that they both hoist, but don't initialize the same.
3 replies 0 retweets 7 likes
Mathias Bynens Retweeted getify
I figured that’s what you meant, but that context was certainly not clear to everyone: https://twitter.com/Fozzleberry/status/1101844699512475649 …
You’re complaining about inaccurate statements: https://twitter.com/getify/status/1101524536804233216 … Seems weird to then go and make some of them yourself in the very same thread. 
Mathias Bynens added,
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.
JavaScript, HTML, CSS, HTTP, performance, security, Bash, Unicode, i18n, macOS.