Jake and Surma take a deep dive into the world of variable scoping in JavaScript. var vs const/let and scripts vs modules.
Original source
Jake and Surma take a deep dive into the world of variable scoping in JavaScript. var vs const/let and scripts vs modules.
Original source
20 responses to “Scope in JavaScript – HTTP 203”
yet again another great video youtube recommended to me even though i have already seen it
Seeing the with statement reminded me of the JavaScript-Based Style Sheets W3C proposal. That thing was full of with statements.
Also, a var declared in global scope overrides an existing window property:
window.foo = { a: 'a' };
var foo = { b: 'b' };
console.log(window.foo);
console.log(foo);
console.log(window.foo === foo);
// outputs:
// {b: "b"}
// {b: "b"}
// true
self === window and self === globalThis are both true
Great video but if only you had a textual summary or similar to help people memorize what the video was about it would be much better.
A series like this on the Android channel pls x.x
WordPress uses this script global scope to pass PHP variables to scripts
07:55 "a case where self and window are not equal", I guess it's the case you mentioned previously, i.e. a worker? window is not available (and thus `undefined`) in workers, but self is.
The only case I could think of regarding self and window is iframe:
window.self !== window.top
I remember watching a video by LiveOverflow about a (maybe google) CTF challange with `with`
Very good!!! This is undoubtedly one of the important resources for developers today. Thank you for teaching us
Great format! I like how JS concepts are explained in a dialogue between two engineers. This is definitely more catchy and entertaining that listening a solo talk.
I love your videos is so educational and fun! The catch have a function behavior being a block, shortcut implementation, like typeof is an expression that takes a statement not a param but can written as function call but don’t behave like, ah love those WAT from JS 🙂
Btw the global context refer to globalThis, I think you meant const/let are in the global scope (block) but not in the context.
Another dose of HTTP 203…. I’m saved!
thats some messy shit
There was no "self" back in those days, especially for closures it had to be defined as var self = this;
Great videos tho
self and window not equal? ye.. iframes
Comment: I officially declare this to be good content.
Now I'm wondering what happens with variables declared inside with without var , in all those cases…
I was so happy that I guessed both with and the catch correctly! The only time I will get a question from google right…