• Thursday , 2 April 2020

JavaScript Let vs Var vs Constant | Mosh

Code Canyon



JavaScript Let vs Var vs Constant –

🔥Get the COMPLETE course (83% OFF – LIMITED TIME ONLY): http://bit.ly/2M1sp4B

Subscribe for more videos:
https://www.youtube.com/channel/UCWv7vMbMWH4-V0ZXdmDpPBA?sub_confirmation=1

Want to learn more from me? Check out my blog and courses:

http://programmingwithmosh.com
https://www.facebook.com/programmingwithmosh/


Original source

3d Ocean

Related Posts

39 Comments

  1. Funny Clips
    January 2, 2020 at 20:42

    What a explanation boss!! I have been cleared the let vs var. Before watching the video i was in a confusion about that. But now i have been cleared that for your great tutorial. God bless you. Thanks

  2. A Centauri
    January 2, 2020 at 20:42

    A fucking rant about fucking const vs fucking let :
    https://jamie.build/const

  3. mELtingaWay __
    January 2, 2020 at 20:42

    Disliked video because you didn't explain const

  4. Ken
    January 2, 2020 at 20:42

    In addition to everything mentioned in this video, let has reassignment protection. What I mean by this is the following:

    If you declare a variable:

    var test = 'test';

    and later have:

    var test = 'new test';

    then the variable test will be reassigned, sometimes without your knowledge.

    with let, this does not happen. If you declare:

    let test = 'test';

    then later:

    let test = 'new test';

    You'll hit a error/warning that test has already been declared. Unlike a const however, it can still be reassigned the 'normal' way, which is much more intentional:

    test = 'new test';

    because you are not using let before the name of the variable, it is clear that you know the variable already exists, and you are reassigning it. This protection helps prevent accidental reassigning of a variable you already declared but then may have forgotten about, and reduces debugging. Yet another reason to use let instead of var!

    note – const cannot be reassigned at all, even using the 'deliberate' way shown above, it is not a variable, but a constant. It does not change.

  5. Gizmo aP
    January 2, 2020 at 20:42

    So using let is more secure? I’m curious, you would only want to limit the variables scope to only where it will be used/accessed?

  6. DijiFlex CyberTech
    January 2, 2020 at 20:42

    Clear and straight to the point

  7. Lucas Almeida
    January 2, 2020 at 20:42

    thanks 😀 quick and well explained!

  8. Nick T
    January 2, 2020 at 20:42

    What a wonderful way to explain. loved it.

  9. wotanman
    January 2, 2020 at 20:42

    I hate to sound stupid but why if the loop terminates at i < 5 is the sixth var 5 and not 4? I thought the loop terminate. Does this mean the i++ is the last bit of information at the end of the loop however it wouldn't display it on the console? (meaning the value of i at 5 is assigned but not printed?

  10. Levelonesucks
    January 2, 2020 at 20:42

    I'm at complete beginner level, been learning only for a couple hours. So I don't know enough to know why you would even want to have variables be block scoped instead of having all variables be global and each of them having a different name. To me seems like the latter would be easier to work with so I can remember what each variable does better but I since i'm so new I will just trust you.

  11. Petros Petrosyan
    January 2, 2020 at 20:42

    What's the difference between using “let” and “var”?
    <a href="https://stackdev.io/question/1010/whats-the-difference-between-using-let-and-var-1"

  12. Milos Miric
    January 2, 2020 at 20:42

    Hi, what color theme are you using for VSCode? Thanks

  13. Pouya Jabbarisani
    January 2, 2020 at 20:42

    Hi Mosh,
    what is the name of your VSCode theme?

  14. Abhishek shah
    January 2, 2020 at 20:42

    Where can I find more info about the function encapsulation? Now I'm curious

  15. şüheda ertürk
    January 2, 2020 at 20:42

    Mosh is the best!!!

  16. iNSIDE the mirror
    January 2, 2020 at 20:42

    I am very curious how that loop at 1:30 managed to count to 5.

    Bro….

  17. 眩暈夢
    January 2, 2020 at 20:42

    I came here to learn about const. I left without that knowledge.

  18. Rooks14
    January 2, 2020 at 20:42

    What's the concern with var if you really need it althrough out the function scope?

  19. Sumon Chandra Shil
    January 2, 2020 at 20:42

    Awesome. I understood very well.

  20. Moaz El-sawaf
    January 2, 2020 at 20:42

    Thanks a lot <3

  21. Pranav Patil
    January 2, 2020 at 20:42

    Sir can you please make a video on Closures in JS..

  22. Siddhartha Shankar Barik
    January 2, 2020 at 20:42

    nice explanation ..

  23. Rana Akbar
    January 2, 2020 at 20:42

    lmao horrible, doesnt even cover Constants as per the title.

  24. Gamal Abdall
    January 2, 2020 at 20:42

    Thank you so much, that was crystal clear.

  25. Reza Mohseni
    January 2, 2020 at 20:42

    Mosh jan, you should add WHY bloating the "window" let say or other objects with variables and functions is bad. watching your video, a novice would think, "well, why would having access to data outside of a scope bad?!", which is a valid and good question. Otherwise, a very nice video, thanks 🙂

  26. Chandan Kumar Thakur
    January 2, 2020 at 20:42

    let sayHi =function() { console.log('hi');}

  27. Janus
    January 2, 2020 at 20:42

    You didn't explain what const does.

  28. MrRossss1
    January 2, 2020 at 20:42

    Hi Mosh. If var attaches variables to the window/global object where are those declared with let/const attached to if they're not declared inside a block? Thanks, great videos btw

  29. Devlin
    January 2, 2020 at 20:42

    More like just "var vs let" than "var vs let vs const"…

  30. m.nageh
    January 2, 2020 at 20:42

    what if you just used
    test = 'color';

  31. Cicero Fonseca
    January 2, 2020 at 20:42

    Awesome…you explained it so simple. Finally, I got the difference!

  32. Interstate Love
    January 2, 2020 at 20:42

    You are awesome Mosh!!!

  33. Mohit Negi
    January 2, 2020 at 20:42

    Finally. I got it.

  34. Mike Palazzo
    January 2, 2020 at 20:42

    Great video, thank you. So if I declare a variable using let in the global scope, does that have the same scope as the window object?

  35. MichelandKim van Essen
    January 2, 2020 at 20:42

    The award for lost clear explanation ever goes to you sir!

  36. 45above50below
    January 2, 2020 at 20:42

    I'm learning JavaScript and your videos answer many questions, in a concise manner, that I still have after many months. Thank you for posting these on YouTube and helping us all become better! I appreciate it!

  37. CuddlyBunion341
    January 2, 2020 at 20:42

    I will still be using var… but still thanks for the explanation… :]

  38. Hardik Motwani
    January 2, 2020 at 20:42

    The best explanation of let and var keyword so far, Thanks

  39. Equality
    January 2, 2020 at 20:42

    10/10 your performance

Leave A Comment

You must be logged in to post a comment.