Тёмный

Differences Between Var, Let, and Const 

Web Dev Simplified
Подписаться 1,6 млн
Просмотров 190 тыс.
50% 1

You have probably watched many different tutorials, and you may have noticed that some tutorials use var to declare variables while others use let or even const. It can get confusing quickly on what the differences are between the keywords, so in this video I am going to be explaining everything you need to know about var, let, and const. I will be going over their differences as well as explaining what situations you should use each keyword.
If you have any suggestions for a JavaScript topic, please let me know in the comments below.
Let vs Const vs Var Article:
blog.webdevsim...
Twitter:
/ devsimplified
GitHub:
github.com/Web...
CodePen:
codepen.io/Web...
#VarVsLet #JavaScript #WebDevelopment

Опубликовано:

 

27 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 216   
@ianoliver6828
@ianoliver6828 3 года назад
You have a super rare skill. It's rare to find someone who is both a skilled programmer AND a skilled teacher / communicator. Thank you for your videos
@olegfare4625
@olegfare4625 2 года назад
and Zach Efron level of handsome
@sclutzo
@sclutzo 2 года назад
Totally agree!
@samanthawu1637
@samanthawu1637 Месяц назад
I second this!
@camilafloressanhueza7966
@camilafloressanhueza7966 4 года назад
OMG!! I had seen 100000 videos whose explanations were extremely complicated, but you explained it in less than 5 minutes!! Thank you very much
@GoogleAccount-jw1rd
@GoogleAccount-jw1rd 2 года назад
And understandable
@AlexTechie
@AlexTechie 5 лет назад
6:36 I didn't know that. This is why I always watch your videos, even if I think I understand the subject before hand. Great work! 👍
@WebDevSimplified
@WebDevSimplified 5 лет назад
It is a bit counter intuitive based on the name. You can use Object.freeze to create an object that cannot have the properties reassigned, but it will still let you reassign a nested property such as company.ceo.name = 'New name'
@AlexTechie
@AlexTechie 5 лет назад
@@WebDevSimplified thanks for the tip! As I was watching the part I referenced earlier, I was wondering how we would assign constants to the properties of an object, so it's like you read my mind. :D
@dozadetrezire7455
@dozadetrezire7455 2 года назад
You forgot to say one more thing: when you declare a variable with var keyowrd, this automatically creates a property inside the Window ojbject.. so, if you say for example: var x = 1; and after that you say: console.log(window)... you will see that in the window object you will find the property X with the value of 1. Instead, if you declare a variable with let or const, this won't ceate a property inside the Window object. I guess this was also very important to mention!
@Max-nm8ct
@Max-nm8ct 3 года назад
Mate, I must say, your hair is on fleek!
@michaelmaloy6378
@michaelmaloy6378 Год назад
Whenever I see that face, I know useful information is coming my way. Simple, clear, and very helpful. Thank you as always!
@dsvhs93
@dsvhs93 4 года назад
Whenever Kyle comes out with the JavaScript class that he is working on.... I am purchasing it. He is awesome! Thank you Kyle!
@WebDevSimplified
@WebDevSimplified 4 года назад
Thank you for the support! I start recordikg tomorrow!
@AidanJoyce
@AidanJoyce 2 года назад
Would like to say, well done and thank you for a clear and concise explanation of the similarities, differences and when to use, Var, Const and Let. Watched other videos and without doubt, you nail it better here with both explanation and example. Will be watching more of your stuff as this was a great measure stick for the quality of teaching. Keep up the great work.
@tonic.9234
@tonic.9234 2 года назад
I never knew var worked like this, and I've been using Javascript almost daily for over 2 years. I always assumed it worked like let because I have a background in other programming languages and assumed it's scoping worked the same. So wild! Thanks for the clarification!
@pratikthorat3480
@pratikthorat3480 3 года назад
This is the best explanation I've ever seen. I do know the differences yet I learnt something new
@pooja6380
@pooja6380 Год назад
learn so much important points and the actual difference ....thanks a lot
@samanthawu1637
@samanthawu1637 Месяц назад
You were born to teach! Awesome!
@derrick3534
@derrick3534 5 лет назад
man you are teaching the things that are not widely discussed which is why i am going to subscribe. You have a true gift of teaching in simple terms. i enjoy your channel, especially the tutorial on promises
@WebDevSimplified
@WebDevSimplified 5 лет назад
Thank you! I try to cover the topics that I know confused me or other people I know, because those will be the most helpful for others.
@theNikijspictures
@theNikijspictures Год назад
Really good explanation, for beginner level - if reading info only in text (with no visual examples), it gets confusing quickly on this topic. Cheers😉
@therealbrucewayne24
@therealbrucewayne24 2 года назад
Yes I did learn something thank you very much man it was hard for me to understand this but you explained it in like less than 10 minutes lol you have a good day too :)
@coderbhai4832
@coderbhai4832 2 года назад
1)Declaration Let variable in a {} block scope can't be access outside of it 2)let name = value1, let name = value2, can't redeclare let twice Instead of this should be written name=value2; 3)let can be change it’s value const can't as it is constant but it can change its object value.🙃
@chalk1007
@chalk1007 2 года назад
yeah, I was a little confused aswell but this video was made in 2018
@dozadetrezire7455
@dozadetrezire7455 2 года назад
You forgot to say one more thing: when you declare a variable with var keyowrd, this automatically creates a property inside the Window ojbject.. so, if you say for example: var x = 1; and after that you say: console.log(window)... you will see that in the window object you will find the property X with the value of 1. Instead, if you declare a variable with let or const, this won't ceate a property inside the Window object. I guess this was also very important to mention!
@injector6926
@injector6926 3 года назад
Best Web Development I seen evrr
@bozok1903
@bozok1903 27 дней назад
Very clear explanation. Thank you for that.
@jahneychriast2141
@jahneychriast2141 4 года назад
தெளிவான விழக்கம் நன்றி 🙏🏽
@manojbharadwaj456
@manojbharadwaj456 4 года назад
That's so motivating. Because nobody understood that!
@sadhappy8860
@sadhappy8860 11 месяцев назад
Super clear explanation, many thanks
@videospromoter5884
@videospromoter5884 4 года назад
Checked 10s of video and this video told me hmm you understand this now . say thanks to him :) Thanks Dude
@JEffinger
@JEffinger 2 года назад
Thank's bro that was a really clear explanation.
@baliyachtservices7505
@baliyachtservices7505 2 года назад
I was wondering just that! Thanks so much
@ImHansana123
@ImHansana123 5 месяцев назад
The good old days when we didn't have chatgpt.❤️
@WebDevJapan
@WebDevJapan 4 месяца назад
lol true, but I like seeing a human explain it sometimes. Even though I can get quick answers from Professor GPT, I've made it a habit to watch one short intructional video like this everyday.
@aadityakiran_s
@aadityakiran_s Год назад
I came from C#. It's pretty simple there. Use var for what you wanna change, const for what you don't wanna change; variable and constant. Simple language for simple people.
@santra528
@santra528 4 года назад
This is complete explanation of let vs const vs var I have ever seen. Thanks Kyle 😊
@somtovitus
@somtovitus 3 года назад
Best video on this topic
@nessparadis6948
@nessparadis6948 Год назад
Great video. Succinct, clear to understand, and I learned a lot. Thank you.
@nobitalazy9791
@nobitalazy9791 2 года назад
you are a rare gem my friend!!!
@harmez7
@harmez7 2 месяца назад
I need a video that of explaining who these Bob and Sally are, you're using them everywhere :3 Im curious af for real
@mayorb37
@mayorb37 Год назад
You make a wonderful work 👍👍👍👍👍 thanks
@rajlakshmijoshi
@rajlakshmijoshi 2 года назад
Thnks for the detailed vid, just one correction: At 5:35-> const does not allow to 're-declare' the variable, actually should be const does not allow to 're-assign' the variable, but let do.
@jankiramulu
@jankiramulu Год назад
Wonderful explanation.. Than you....
@ev_dash
@ev_dash Год назад
Your videos are helping me out alot! Thank you ❤
@alex_blue5802
@alex_blue5802 Год назад
I used to see people saying that you should use const only if you have a specific need for a variable to remain constant. Nowadays it seems like people always want to use const as a default and I don't like that as much.
@СашаТюменцев-ш9ь
@СашаТюменцев-ш9ь 2 года назад
huge thanks for the explanation, only you made it clear to me!
@placeholder_name321
@placeholder_name321 3 года назад
so so simple. Finally.
@xilliman
@xilliman 3 года назад
im declaring every variable as const and then change it to let if i have to reassign them. this makes the code much safer. i don’t use var anymore
@kushagraraj3163
@kushagraraj3163 Год назад
you r jordi of webdev !!!!!!!
@kazeemalatishe3828
@kazeemalatishe3828 2 года назад
Thanks a lot. You explain things really well.
@agaming7888
@agaming7888 Год назад
thanks for this now i know what to do 👍👍👍👍
@wr1818
@wr1818 2 года назад
thankyou for all the amazing explaining!
@derickbank1064
@derickbank1064 3 года назад
Thank you for the explanation. Well explained. !
@pashashyba5006
@pashashyba5006 2 года назад
Quite easy to understand. Thanks
@ЕдвардГригорян-н6к
great explanation. TY!
@דודבינימינוב-י5ג
@דודבינימינוב-י5ג 4 года назад
you are amaizing
@halofreak644
@halofreak644 3 года назад
You the real MVP
@oceanmind1793
@oceanmind1793 2 года назад
You made it so clear. Thanks a lot
@vikumravinayake1882
@vikumravinayake1882 3 года назад
Problem solved Thank you very much. Ur a good explainer....
@jimilittle
@jimilittle 2 года назад
That was awesome. Thank you
@guillaumedupont2902
@guillaumedupont2902 3 года назад
This was SO helpful. Thank you so much!
@ruslankovalov8292
@ruslankovalov8292 3 года назад
Thanks God we have you to explain this!! thanks!! A lot! A mean that)
@andreastewart6133
@andreastewart6133 2 года назад
Helpful. Thank you.
@NashBrooklyn
@NashBrooklyn Год назад
wait up! const also allows to assign value outside of block - as many times you would need to assign such value that cannot be changed by hackers - for instance a waiting time to acept a trip request must be 1 minute only - so if a hacker wishes to change that to 60 minutes - const will not let that to happen - const is great to use in many solid inflexible math routines - that can happen all over the code - so if you set the earth radius to its value as per books - then using const will assure it wont be changed by any accidents or bugs in code -
@surendergaini3365
@surendergaini3365 2 года назад
GOOD explaintion
@RS-nz6rn
@RS-nz6rn 3 года назад
Thanks for clarifying.
@andreas-wismann
@andreas-wismann 2 года назад
Great! Suggested topic while you're at it: Semicolons in JS - use or omit?
@andyarellano7474
@andyarellano7474 2 года назад
Thank you so much bro.
@hoakeen
@hoakeen 2 года назад
Awesome tutorials! Thank you!
@53strat55
@53strat55 3 года назад
Solid video!
@RakeshBitling
@RakeshBitling 3 года назад
can you please cover topic related to redis cache along with aws
@tomschwrs
@tomschwrs Год назад
Great Video!
@deepkar9794
@deepkar9794 2 года назад
thanks kyle
@SumitSinghrao
@SumitSinghrao 3 года назад
Could you also explain if we declare a variable without var, let and const? Could you also make video on 'this' keyword.
@redpadweb
@redpadweb 2 года назад
Thank you so much.
@shresthsrivastava27
@shresthsrivastava27 3 года назад
Awesome explanation !
@youareuglybuti
@youareuglybuti 2 года назад
Thank you man, was struggling to understand these basic concepts. You are a lifesaver.
@Garentei
@Garentei 3 года назад
I think const shouldn't let you modify anything... smh at JS consistency. Great video!
@NedumEze
@NedumEze 3 года назад
I love your approach so much. Thank you. I do have a fundamental problem though. Maybe you can consider making video of it. It is this: When I create an external JS file, and I have in it, codes like functions, etc in it, only the first code or function works! What should I do to ensure that different codes intended to fire at different Listeners, in the same file, work?
@langgs
@langgs 7 месяцев назад
THNX!!!
@FredRosa
@FredRosa 3 года назад
Great tutorial, thanks!
@chriscalver8595
@chriscalver8595 10 месяцев назад
Thanks
@hanntongfong1226
@hanntongfong1226 3 года назад
Great work! 👍
@upcom1ng116
@upcom1ng116 3 года назад
For those who get an error "SyntaxError: Identifier 'letVariable' has already been declared" Look for another video "var, let and const for beginners (ES6)"
@johanledel1407
@johanledel1407 4 года назад
Thank you!
@kamalsyed4237
@kamalsyed4237 4 года назад
loved it! Thanks.. Const, Let, Var .. it is :)
@themixmaster
@themixmaster 3 года назад
thanks a lot man
@WebDevChallenge-Ethiopia
@WebDevChallenge-Ethiopia Месяц назад
Web Dev Challenge-Ethiopia
@namratadas5569
@namratadas5569 4 года назад
Grt video... can you make videos on concepts such as closures,iffis,apply,call,bind methods...etc?
@soundstation16
@soundstation16 Год назад
This tutorial is superb. and by the way, you're handsome.
@graphic-nations
@graphic-nations 3 года назад
thank you alot
@RMNSH99
@RMNSH99 4 года назад
Thanks Kyle
@ihaseeb_khan
@ihaseeb_khan 4 года назад
Thank you bro, really helpful :)
@VishalSharma-rn7mt
@VishalSharma-rn7mt 2 года назад
Awesome
@akashmadanu3994
@akashmadanu3994 7 месяцев назад
Skip Intro : 0:41
@Thecanadiangamer25
@Thecanadiangamer25 3 года назад
I get it..so let and const are your "idiotproof" code while var is...var kinda like the cooler cousin that your parents tell you to stay away from.
@ev_dash
@ev_dash Год назад
So is it safe to just never use "var"? I cant think of any situations where you would need it.
@madhukari9304
@madhukari9304 4 года назад
Thanks bro
@quickmaths4762
@quickmaths4762 2 года назад
5:35 is wrong no? you say const does not allow you to redeclare a variable. But you meant reassign right? (redeclare is also forbidden with let...)
@simiyutube
@simiyutube 4 года назад
Thanks!
@flashbond
@flashbond 3 года назад
for (const i=0; i
@atifasadkhan
@atifasadkhan 3 года назад
let searchInsertion = (array) => { for (let i = 1; i < array.length; i++) { let currentVal = array[i]; for (let j = i - 1; j >= 0 && array[j] > currentVal; j--) { // console.log(array[i], array[j]); array[j + 1] = array[j]; // console.log(array); } array[j + 1] = currentVal; } return array; }; console.log(searchInsertion([2, 1, 9, 76, 4])); In this case until and unless I declare j as var or declare it above it wont work but I dont want to declare it above!!!
@NehaGupta-fd8hs
@NehaGupta-fd8hs 5 лет назад
Great Stuff!
@WebDevSimplified
@WebDevSimplified 5 лет назад
Thank you!
@letsgetto1millwithoutvids
@letsgetto1millwithoutvids 2 года назад
Good video finally understand and I could have used var for something I needed instead of saving it to local storage and grabbing it after 🤦‍♀️
@chvidya8585
@chvidya8585 4 года назад
const obj = { name:"cat" } obj.name = "dog"; obj.age = 22 console.log(obj) ------------------------------ let obj2 = { name:"cat" } obj2.name = "dog"; obj2.age = 22 console.log(obj2) we can update bout let and const
@samankayhanian3888
@samankayhanian3888 2 года назад
champ!
@sayantaniguha8519
@sayantaniguha8519 3 года назад
for(var i=1;i
@TusharBorawake
@TusharBorawake 2 года назад
var can be attached to global window object but let and const are not. Where actually those get stored ?
@pipitgusmayanti8342
@pipitgusmayanti8342 2 года назад
The same way `var` variable is stored inside a function
@maciej12345678
@maciej12345678 2 года назад
6:38 you mean redefine or redeclare -- with let you cant redeclare with new value you can redefine with new value
@joymugao9863
@joymugao9863 11 месяцев назад
Your blinking is a bit distracting but I understood the content.
Далее
JavaScript ES6 Arrow Functions Tutorial
9:32
Просмотров 833 тыс.
Reference Vs Value In JavaScript
15:12
Просмотров 183 тыс.
ДЕНЬ УЧИТЕЛЯ В ШКОЛЕ
01:00
Просмотров 297 тыс.
The Most Important Skill You Never Learned
34:56
Просмотров 206 тыс.
JavaScript var, let, and const explained
11:56
Просмотров 24 тыс.
Learn Closures In 13 Minutes
13:22
Просмотров 67 тыс.
Let vs. Const in JavaScript  - What's the Difference?
6:09
The Weird History of JavaScript
12:09
Просмотров 1,2 млн
5 JavaScript Concepts You HAVE TO KNOW
9:38
Просмотров 1,4 млн