var let const in Javascript Scope | Understanding Global Local Function Block Scope

preview_player
Показать описание

In this video we'll compare the keywords var, let, and const in JavaScript which also requires an understanding of JavaScript scopes such as global scope, local scope, function scope, and block scope.

✅ Quick Concepts outline:
var, let, and const in Javascript
(00:00) Intro
(0:30) What makes var different
(1:40) What makes let different
(2:05) What makes const different
(2:35) A discussion of scope
(2:50) Global Scope
(3:25) Local Scope
(3:35) Block Scope
(4:00) Function Scope
(4:45) Local Scope variables declared with let or const are not available in global scope
(6:00) Nested block scope inside of a function
(7:05) Global scope variables are available in local scopes
(8:00) Global scope is available to all scopes
(8:25) If statements have block scopes
(8:35) for loops have block scopes
(8:45) switch statements have block scopes
(9:00) Review of scopes so far...
(9:50) A 2nd Example of global, function, and block scopes
(14:40) Note: var is function scoped; const & let are block scoped
(15:45) Review with helpful graphic :)

📚 Further Reading:
MDN Web Docs:
Eloquent JavaScript Chapter 3:

📺 More Beginner JS Videos:

✅ Follow Me:

#var #let #const
Рекомендации по теме
Комментарии
Автор

Very detailed perfect lessons you have on your channel! I wish I found your channel earlier because not so many people explain basic foundational things so well. Good work :)

neatunet
Автор

The best explanation of scope I have seen so far.
It could have avoided me all those "undefined" errors a few weeks ago.
Very good.

CondeAlberto
Автор

Sometimes, all you need is a video and it does the work of a whole pdf. Thanks man.

movierecommendation
Автор

Thanks, Dave !!
This one came via a link from my lecturer, but I have worked thru a number of your multi-hour videos previously. Your explanations have helped me to understand many of the core concepts of JavaScript programming and web development.

someguy
Автор

Wow! What a thorough explanation. Amazing Dave; by far the best on YouTube.

farazk
Автор

Thanks Dave! Been looking at several videos on scopes by far the best.

bbalot
Автор

Very understandable thanks a lot I liked your video thanks for creating this videos

bekhruzilhomov
Автор

Can't recommend enough your channel, well thought explanations, concise, thanks a lot for sharing

VladimirJovana
Автор

Ive been having trouble with scope for the absolute LONGEST, everything else in javascript has made sense except that. The second example at 9:50 was spot on.

blurrywaters
Автор

Roadmap redirected me to your channel, what a tutorial!

E-business-cp
Автор

Amazing explanation. Great work Dave. Thank you.

FredRosa
Автор

This is so detailed and easy to understand.Thank you

StellaOloo
Автор

Wonderfully compiled and delivered. Thanks for giving such crystal clarity in these fundamentals..

yatin
Автор

this is the best explanation on scope I have ever seen 🎉

dr_corrupt
Автор

Thank you for explaining the concept of variable leaking ! Never knew this happens with var

RahulSharma-oefy
Автор

thank you so much, your clear explanation made me understand the difference between var, let and cons. :)

mohammadahmedragab
Автор

It might be considered as not the easiest topic but with your explanation it's clear! Thank you!

Grihlo
Автор

Comment made after watching a useful video so I don't forget what it was about #2.

Global scope -> Variable accesible through all the code and they are outside any function
Block scope -> Variable inside curly braces (as things in for)
Function Scope -> Variable inside a function
The last two cannot be accessed outside the declared place, for function, it'll return undefined, for block scope, it'll have an error

citlaliserratos
Автор

Thank you, Dave! At 10:45 you marked three words "global" which are on seperate lines, and changed them simultaneously. How did you do that?

tymo
Автор

Мне очень жаль, что мало понимаю английский язык. Но я все равно понимаю эти уроки потому что вы объясняете очень хорошо и детально огромная вам благодарность

ezozaezoza