The Difference Between var and let in JavaScript

preview_player
Показать описание
ES6 or ES2015 provided a new way for declaring variables. This video examines the difference between var and let in JavaScript. Those differences have to do with variable scope and hoisting.

For a complete list of all our tutorials:

Take the Learn Modern JavaScript: Getting Started or the Learn Modern JavaScript: Advanced Topics courses at a huge discount:
Рекомендации по теме
Комментарии
Автор

I just finished the Getting Started training from Udemy and starting the advanced. Recommended for everyone who is looking for JS training.

polliluiz
Автор

Hello 👋 I just want to let you know I have purchased the Advanced JavaScript Class and I am really happy to start my journey. You are really amazing 😉 and I really like what you do. I send you this message as a reminder that const and let are not exotic features of JavaScript. As you know from my previous messages I am kind of in love with JavaScript and all of it’s new features (I should probably become a JS evangelist because it’s a true religion to me) I would like to first say that I respect your experience and I know that you are an old school developer and I am a n00b ... ;-) But I would love you to reconsider using const to remplace let or var everywhere except when you know you will need to reassign the same variable in your code (in fact in your case it could be different because you have small examples to quickly show some functionality) the const keyword should not be confusing if well explained to newcomers (and since you are so good at explaining people will not be confused let me explain) of course it’s probably important first to do the parallel with other language where it would signal immutability obviously in JavaScript it is different... To be able to be comfortable with that special friend the way to understand it and then the way you should probably explain it I think is at first point out that objects are references and that cosnt set a constant reference to the object location in memory and that’s what will not change the key here is the possible optimization in the interpreter if this location in memory is set permanently with const after this is said then that notion of constant is more easy to accept than if pointing first that it’s not useful because you can change your object’s values even using the word const ... Obviously it is super important to mention but by mentioning it first it sets in the mind of newcomers that JavaScript is that weird beast and that everything is illogical with that language... Evidently I was previously just saying “religion” in a metaphorical way and therefore JavaScript is not dogmatic (au contraire) but I would like to see the people who are new to JavaScript being introduced to the const keyword in a way that won’t make it look stranger than he really is ... const to me should be the new var all the time and let should be the exception used for primitive that will need to be reassigned... but it’s my point of view and I hope you will find something useful for your students in flipping around your point of view and paradigm regarding what costs should really mean to JavaScript development (I should do my first post on medium haha it’s long enough to be monetize LoL 😂)

Luxcium
Автор

These are such good examples - I am signing up for your advanced classes too! Thank you

tanishamatthews
Автор

Every UI developer should see these tutorials!

ruchirai
Автор

Hi Stephen. I understand let and const are hoisted into the TDZ and allocated seperate memory until initialized and put into a seperate memory block space rather than on the global object. Is this memory space for let and const not accessible in the browser in the same way that var variables can be viewed by expanding the window object? It looks to me like let and const memory is invisible in the browser and you can't go into devtools and look for all your initialized let and const variables? Why is this? Also when typing a let variable into the console that already exists - why does the console know that you are not referencing a variable on window and to look at the block memory?

russelldriver
Автор

Thanks for the simple and easily understood examples.

CameronChardukian
welcome to shbcf.ru