Javascript Scope Tutorial – What Makes Javascript Weird…and Awesome Pt 4




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”

  1. 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 πŸ™‚

  2. 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.

Leave a Reply