Scope and Context are in every language, but because Javascript is always firing callbacks and running asynchronous tasks, it’s easy to lose sight of what scope & context you’re in.
Scope and context are not the same thing. Scope is variable access – what variables the current piece of code has access to, context is the value of `this` – when you type `this` in your code, what object is it referring to?
This javascript tutorial covers scope and how it plays out in all of the functions that you create.
Watch the full playlist:
#javascript, #javascriptTutorial, #javascriptScope, #webDevelopmentTutorial
Original source
25 responses to “Javascript Scope Tutorial – What Makes Javascript Weird…and Awesome Pt 4”
Remember Contexthis
haha,you are the best!
Super clear, efficient, and concise! Thank you!
thank you!!
1:21 When you type window.a === a are you really doing an identity check? I think you might give the impression that you are doing a check for identity rather than simply for value -if you see what I mean.
I think the equality operators check identity only on objects -not primitives -so you're just checking the value of the variable against itself?
Thanks for the vid π
Very well explained! You are doing a good job. Congratulations!
The child cookies explanation is sublime, can't believe I've never come across it before!
thanks! helped lots
I love you…………………… for making this video
Fucking amazing bro. Thanks a lot
Cookie explanation changed my whole life! Ha. Good stuff man! Seriously such a simple way to explain that to others.
There is a mistake in the video. Chrome didn't throw error at 6:50 because 'a' was not defined in root scope or more specifically due to line:13 but it was line:8 which was faulty you cannot create variables in root scope from child scopes with 'use strict' mode enabled.
What 'a = 2;' in child scope does is, it looks for the variable in current scope, if it is not then create it in root scope first and then handles the process accordingly which is prone to error. for example: if a programmer is under the impression that he has declared it somewhere but actually he has not, then it produces unexpected behaviours.
Loved the cookie explanation!
amazing ??
scope for cookies however is different: as a child you would 1st look in your parent's jar π
so i'ts only one way relevant π
Just laughed out loud for the first time during a coding tut. The parent.child.cookies explination was a stroke of genius. As a father of two, I'll not soon forget scope.
Very clear explanation, awesome!
Holy shit charge your battery!
Great and so funny! π
Thank you very much >> you've made it crystal clear
thank you thank you :))
call this video variable hoisting
superb example – parent-child-cookies…..
Clear and precise. Excellent!
cookie analogy on point!
OMG that was awesome!! Lmao….. parent/child cookies analogy was spectacular… still laughing..