Differences Between Var, Let, and Const

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2018
  • 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.webdevsimplified.com/202...
    Twitter:
    / devsimplified
    GitHub:
    github.com/WebDevSimplified
    CodePen:
    codepen.io/WebDevSimplified
    #VarVsLet #JavaScript #WebDevelopment

ความคิดเห็น • 209

  • @ianoliver6828
    @ianoliver6828 3 ปีที่แล้ว +219

    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 ปีที่แล้ว +9

      and Zach Efron level of handsome

    • @sclutzo
      @sclutzo ปีที่แล้ว +2

      Totally agree!

  • @camilafloressanhueza7966
    @camilafloressanhueza7966 4 ปีที่แล้ว +153

    OMG!! I had seen 100000 videos whose explanations were extremely complicated, but you explained it in less than 5 minutes!! Thank you very much

  • @Max-nm8ct
    @Max-nm8ct 3 ปีที่แล้ว +40

    Mate, I must say, your hair is on fleek!

  • @jthomasaurus
    @jthomasaurus 4 ปีที่แล้ว +6

    Another super-clear explanation. Love your video style, brevity, and way of explaining everything. Plain and simple!

  • @dorothyglade9087
    @dorothyglade9087 2 ปีที่แล้ว +1

    This was great, you speak at just the right speed and your voice is clear. This really helped me and my husband with something in our bootcamp.

  • @TheSlimSh4dy
    @TheSlimSh4dy 3 ปีที่แล้ว +11

    Thank you for the clear explanation! Currently, I'm learning HTML, CSS & Javascript and if I don't understand something, I'm firstly looking at your channel to find an explanation. If it doesn't exist on your channel, then I'm searching in other sources. You are a very good teacher, your videos are short, consistent and very clear, without any unnecessary content. Thank you very much for sharing your time to make these videos.

  • @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.

  • @raaghavendrahm4883
    @raaghavendrahm4883 3 ปีที่แล้ว

    I am just starting with JS and I was stuck with this like hell. You made it so clear. Thanks a lot!!

  • @AlexTechie
    @AlexTechie 5 ปีที่แล้ว +59

    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 ปีที่แล้ว +13

      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 ปีที่แล้ว +4

      @@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

  • @pratikthorat3480
    @pratikthorat3480 2 ปีที่แล้ว +1

    This is the best explanation I've ever seen. I do know the differences yet I learnt something new

  • @santra528
    @santra528 4 ปีที่แล้ว

    This is complete explanation of let vs const vs var I have ever seen. Thanks Kyle 😊

  • @tonic.9234
    @tonic.9234 2 ปีที่แล้ว +1

    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!

  • @rohit9969171579
    @rohit9969171579 4 ปีที่แล้ว +11

    It was very crystal clear explanation thank you.

  • @youareuglybuti
    @youareuglybuti ปีที่แล้ว

    Thank you man, was struggling to understand these basic concepts. You are a lifesaver.

  • @dsvhs93
    @dsvhs93 3 ปีที่แล้ว +1

    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  3 ปีที่แล้ว

      Thank you for the support! I start recordikg tomorrow!

  • @jorgefrias7889
    @jorgefrias7889 ปีที่แล้ว

    Amazing explanation. Simple and straight to the point. Thank you!

  • @moonlightCR7
    @moonlightCR7 ปีที่แล้ว

    Thanks a billion, Kyle for explaining the difference among these keywords.

  • @thecoderabbi
    @thecoderabbi 3 ปีที่แล้ว +1

    Thank you very much Kyle, This is great. Very explicit. I think I would begin using the 'const' instead of the 'var'
    Thanks ✌️

  • @gqntexas
    @gqntexas 2 ปีที่แล้ว

    Great great explanation.. you always here that the differences is the 'block scope' and then wonder, well, like within an if or for loop, but nobody else ever says that...

  • @B3ASTM0DE1
    @B3ASTM0DE1 5 ปีที่แล้ว +8

    This video came just in time. We are going through Javascript and JQuery right now in my bootcamp!

    • @WebDevSimplified
      @WebDevSimplified  5 ปีที่แล้ว +3

      I'm really glad to hear. If you run into anything that confuses you in the bootcamp feel free to let me know, and I can try to help or make a video on the topic.

    • @B3ASTM0DE1
      @B3ASTM0DE1 5 ปีที่แล้ว

      @@WebDevSimplified Awesome will do!

  • @pooja6380
    @pooja6380 ปีที่แล้ว +1

    learn so much important points and the actual difference ....thanks a lot

  • @sadhappy8860
    @sadhappy8860 8 หลายเดือนก่อน

    Super clear explanation, many thanks

  • @dozadetrezire7455
    @dozadetrezire7455 2 ปีที่แล้ว +23

    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!

  • @dacfniel5442
    @dacfniel5442 4 ปีที่แล้ว

    You are the best teacher on TH-cam.

  • @baliyachtservices7505
    @baliyachtservices7505 2 ปีที่แล้ว

    I was wondering just that! Thanks so much

  • @borislavaborisova7274
    @borislavaborisova7274 ปีที่แล้ว

    Thank you! This video was very helpful. Just what I needed.

  • @derrick3534
    @derrick3534 5 ปีที่แล้ว +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 ปีที่แล้ว +2

      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.

  • @nessparadis6948
    @nessparadis6948 ปีที่แล้ว

    Great video. Succinct, clear to understand, and I learned a lot. Thank you.

  • @guillaumedupont2902
    @guillaumedupont2902 3 ปีที่แล้ว

    This was SO helpful. Thank you so much!

  • @injector6926
    @injector6926 3 ปีที่แล้ว

    Best Web Development I seen evrr

  • @JEffinger
    @JEffinger ปีที่แล้ว

    Thank's bro that was a really clear explanation.

  • @user-se6ct5zu2f
    @user-se6ct5zu2f 2 ปีที่แล้ว

    huge thanks for the explanation, only you made it clear to me!

  • @bujjivenkateshwarlu6942
    @bujjivenkateshwarlu6942 3 ปีที่แล้ว

    Hey thanks. earlier i had confusion about block scope and Function scope. Now its cleared.

  • @sagarioharvey6910
    @sagarioharvey6910 2 ปีที่แล้ว

    Web dev here in the PH. "Man I love your videos, your making a great impact" //awesome

  • @videospromoter5884
    @videospromoter5884 4 ปีที่แล้ว

    Checked 10s of video and this video told me hmm you understand this now . say thanks to him :) Thanks Dude

  • @ev_dash
    @ev_dash ปีที่แล้ว

    Your videos are helping me out alot! Thank you ❤

  • @somtovitus
    @somtovitus 3 ปีที่แล้ว

    Best video on this topic

  • @JonasGavenas
    @JonasGavenas ปีที่แล้ว

    Great lesson!
    Thank you, perfect explain.

  • @khisus20
    @khisus20 2 ปีที่แล้ว

    This is truly simplified

  • @wr1818
    @wr1818 2 ปีที่แล้ว

    thankyou for all the amazing explaining!

  • @derickbank1064
    @derickbank1064 2 ปีที่แล้ว

    Thank you for the explanation. Well explained. !

  • @kazeemalatishe3828
    @kazeemalatishe3828 2 ปีที่แล้ว

    Thanks a lot. You explain things really well.

  • @weligamage1
    @weligamage1 2 ปีที่แล้ว

    Clear and concise, Thank you

  • @therealbrucewayne24
    @therealbrucewayne24 2 ปีที่แล้ว +1

    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 :)

  • @nobitalazy9791
    @nobitalazy9791 2 ปีที่แล้ว

    you are a rare gem my friend!!!

  • @michaelmaloy6378
    @michaelmaloy6378 ปีที่แล้ว +1

    Whenever I see that face, I know useful information is coming my way.
    Simple, clear, and very helpful. Thank you as always!

  • @user-yi4zd6gh5h
    @user-yi4zd6gh5h ปีที่แล้ว

    great explanation. TY!

  • @tiltify2393
    @tiltify2393 2 ปีที่แล้ว

    finally I understand the difference, thanks man A LOT

  • @priyanshugupta7614
    @priyanshugupta7614 ปีที่แล้ว

    thank you your explanation was very clear

  • @aisana99
    @aisana99 ปีที่แล้ว

    thank you :D you shared more differences than my constructor in my Full-Stack Bootcamp! Will subscribe and watch all other videos of yours

  • @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😉

  • @sandybathwater8385
    @sandybathwater8385 2 ปีที่แล้ว

    So simple, thank you so much! If I search for something and see your face in the results, I am saved. :)

  • @monireachtang712
    @monireachtang712 3 ปีที่แล้ว

    very clear explanation! you are awesome!

  • @jimilittle
    @jimilittle 2 ปีที่แล้ว

    That was awesome. Thank you

  • @mirzashowvik564
    @mirzashowvik564 ปีที่แล้ว

    Great video !!!
    Love it

  • @oceanmind1793
    @oceanmind1793 2 ปีที่แล้ว

    You made it so clear. Thanks a lot

  • @hoakeen
    @hoakeen 2 ปีที่แล้ว

    Awesome tutorials! Thank you!

  • @mayorb37
    @mayorb37 ปีที่แล้ว

    You make a wonderful work 👍👍👍👍👍 thanks

  • @pashashyba5006
    @pashashyba5006 2 ปีที่แล้ว

    Quite easy to understand. Thanks

  • @andreastewart6133
    @andreastewart6133 2 ปีที่แล้ว

    Helpful. Thank you.

  • @tinpham6413
    @tinpham6413 3 ปีที่แล้ว

    Love your channel

  • @RS-nz6rn
    @RS-nz6rn 3 ปีที่แล้ว

    Thanks for clarifying.

  • @jankiramulu
    @jankiramulu ปีที่แล้ว

    Wonderful explanation.. Than you....

  • @shresthsrivastava27
    @shresthsrivastava27 3 ปีที่แล้ว

    Awesome explanation !

  • @placeholder_name321
    @placeholder_name321 3 ปีที่แล้ว

    so so simple. Finally.

  • @letsgetto1millwithoutvids
    @letsgetto1millwithoutvids ปีที่แล้ว

    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 🤦‍♀️

  • @53strat55
    @53strat55 3 ปีที่แล้ว

    Solid video!

  • @FredRosa
    @FredRosa 3 ปีที่แล้ว

    Great tutorial, thanks!

  • @robertoriosmorales7528
    @robertoriosmorales7528 2 ปีที่แล้ว

    awesome explanation

  • @andyarellano7474
    @andyarellano7474 2 ปีที่แล้ว

    Thank you so much bro.

  • @tomschwrs
    @tomschwrs ปีที่แล้ว

    Great Video!

  • @vikasnigam9646
    @vikasnigam9646 2 ปีที่แล้ว

    Gr8 explanation.

  • @ihaseeb_khan
    @ihaseeb_khan 4 ปีที่แล้ว

    Thank you bro, really helpful :)

  • @sebnargeurbrok1374
    @sebnargeurbrok1374 3 ปีที่แล้ว

    well explained, thanks!

  • @redpadweb
    @redpadweb 2 ปีที่แล้ว

    Thank you so much.

  • @jahneychriast2141
    @jahneychriast2141 4 ปีที่แล้ว +2

    தெளிவான விழக்கம் நன்றி 🙏🏽

    • @manojbharadwaj456
      @manojbharadwaj456 4 ปีที่แล้ว +2

      That's so motivating. Because nobody understood that!

  • @NedumEze
    @NedumEze 3 ปีที่แล้ว +1

    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?

  • @hanntongfong1226
    @hanntongfong1226 3 ปีที่แล้ว

    Great work! 👍

  • @agaming7888
    @agaming7888 ปีที่แล้ว

    thanks for this now i know what to do 👍👍👍👍

  • @johanledel1407
    @johanledel1407 4 ปีที่แล้ว +1

    Thank you!

  • @jousufjacob8251
    @jousufjacob8251 2 ปีที่แล้ว

    you are the man ,!

  • @stuartgreen5217
    @stuartgreen5217 4 ปีที่แล้ว

    Been building sites for 30 years and always avoided JS due to pre jquery experience. Am now taking the time to relearn JS and node while I’m at it and I have to say I’m regretting not doing this sooner. I’ve been programming in C# php Perl VB and JS is a peace of cake by comparison .

  • @halofreak644
    @halofreak644 3 ปีที่แล้ว +1

    You the real MVP

  • @kamalsyed4237
    @kamalsyed4237 4 ปีที่แล้ว

    loved it! Thanks.. Const, Let, Var .. it is :)

  • @vikumravinayake1882
    @vikumravinayake1882 3 ปีที่แล้ว

    Problem solved
    Thank you very much. Ur a good explainer....

  • @surendergaini3365
    @surendergaini3365 ปีที่แล้ว

    GOOD explaintion

  • @elkootje
    @elkootje 2 ปีที่แล้ว

    Thank you.

  • @kushagraraj3163
    @kushagraraj3163 ปีที่แล้ว

    you r jordi of webdev !!!!!!!

  • @themixmaster
    @themixmaster 2 ปีที่แล้ว

    thanks a lot man

  • @langgs
    @langgs 5 หลายเดือนก่อน

    THNX!!!

  • @shantanukulkarni8883
    @shantanukulkarni8883 ปีที่แล้ว +7

    Basically, _let_ is _var_ done right.

  • @andreas-wismann
    @andreas-wismann 2 ปีที่แล้ว

    Great! Suggested topic while you're at it: Semicolons in JS - use or omit?

  • @user-ui3ic2fo4j
    @user-ui3ic2fo4j 3 ปีที่แล้ว +1

    you are amaizing

  • @ruslankovalov8292
    @ruslankovalov8292 3 ปีที่แล้ว

    Thanks God we have you to explain this!! thanks!! A lot! A mean that)

  • @coderbhai4832
    @coderbhai4832 2 ปีที่แล้ว +23

    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 ปีที่แล้ว +1

      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!

  • @NehaGupta-fd8hs
    @NehaGupta-fd8hs 4 ปีที่แล้ว

    Great Stuff!

  • @RMNSH99
    @RMNSH99 4 ปีที่แล้ว

    Thanks Kyle

  • @deepkar9794
    @deepkar9794 2 ปีที่แล้ว

    thanks kyle

  • @namratadas5569
    @namratadas5569 3 ปีที่แล้ว

    Grt video... can you make videos on concepts such as closures,iffis,apply,call,bind methods...etc?

  • @graphic-nations
    @graphic-nations 3 ปีที่แล้ว

    thank you alot