Let vs. Const in JavaScript - What's the Difference?

Sdílet
Vložit
  • čas přidán 9. 05. 2021
  • In today's video I'll be explaining the difference between let and const in JavaScript, how they work and when you should use one over the other.
    Enjoy 😀
    For your reference, check this out:
    developer.mozilla.org/en-US/d...
    developer.mozilla.org/en-US/d...
    🏫 My Udemy Courses - www.udemy.com/user/domenic-co...
    🎨 Download my VS Code theme - marketplace.visualstudio.com/...
    💜 Join my Discord Server - / discord
    🐦 Find me on Twitter - / dcodeyt
    💸 Support me on Patreon - / dcode
    📰 Follow me on DEV Community - dev.to/dcodeyt
    📹 Join this channel to get access to perks - / @dcode-software
    If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
    #dcode #javascript

Komentáře • 22

  • @cindymin8723
    @cindymin8723 Před rokem

    awesome, very updated and informational!

  • @SaifRaihan28
    @SaifRaihan28 Před 3 lety

    You’re simply awesome with your simplified explanation. Thanks for teaching us.

  • @guchierrez
    @guchierrez Před rokem

    great simple and concise video.

  • @Mehdi.lol.
    @Mehdi.lol. Před rokem

    Great stuff.

  • @laseangames
    @laseangames Před 2 lety

    Dude thank you for making this video after watching this video, it really helped me understand!!

  • @markopetrovic696
    @markopetrovic696 Před 3 lety

    Can you make video for junior job JS with examples ? You have great videos and explanations :)

  • @neelbanga
    @neelbanga Před 3 lety +4

    Great video! I was wondering if you had any tips for a small programming channel like myself? Thanks!

    • @dcode-software
      @dcode-software  Před 3 lety +2

      Thanks 😁 here's what I've learnt:
      - viewers expect code to be left in the description (I do it much more often now)
      - viewers expect dark mode
      - try to have your code font size as large as possible but not too large that you can't scroll to the left and right
      - keep consistent and don't give up because your videos aren't getting views. Some of my most popular videos didn't do that good for months
      Good luck. I will subscribe

    • @neelbanga
      @neelbanga Před 3 lety +1

      @@dcode-software Thank you for your advice I’ll make sure to incorporate it into my videos! Thank you for subscribing too!!

    • @nikhilmwarrier7948
      @nikhilmwarrier7948 Před 3 lety +1

      @@dcode-software I agree with every single point here, especially with large font size
      Large font size is necessary while you're watching videos on reduced quality in Mobile data on a tiny screen
      Also, I'd recommend adding closed captions/subtitles

    • @neelbanga
      @neelbanga Před 3 lety +2

      @@nikhilmwarrier7948Will do!!

  • @VivekTR
    @VivekTR Před 3 lety +2

    What about performance? Is there a benefit to using const instead of let?

  • @nikhilmwarrier7948
    @nikhilmwarrier7948 Před 3 lety

    Wait, can you modify an array/object declared with "const"?
    I thought const declarations were immutable
    Great video btw!
    I personally like Rust's take on declaring variables though
    In Rust, all variable declarations are immutable by default
    Or you need the additional "mut" keyboard to _specifically_ make it immutable
    It makes you think whether you will really need to mutate the value

    • @dcode-software
      @dcode-software  Před 3 lety +1

      I agree! The idea that you can change objects/arrays declared with "const" is the main reason why I made this video because I've seen "let" used so many times. With regards to constant by default, very true with Rust, and same goes for Kotlin 🙂

  • @blackslashXD
    @blackslashXD Před 3 lety

    what's the difference with var and let though? why is let better than var?

    • @chrisplusplus6232
      @chrisplusplus6232 Před 3 lety +1

      var is old and have problems with reassigning values with different datatype and also block scoping problem, therefore not safe, that is why the jsWorkingGroup change it to use 'let'

  • @chrisplusplus6232
    @chrisplusplus6232 Před 3 lety +1

    'const' is harder to press in keypads than 'let', hahaha, extra two keypress, i hope in the future the jsGroup will change it to 'con' only, haha!

    • @nikhilmwarrier7948
      @nikhilmwarrier7948 Před 3 lety

      Lol yeah, but I just leave it to autocomplete...
      c - o - _enter_
      Three keypresses...

  • @prudhvichinnam1488
    @prudhvichinnam1488 Před 3 lety

    Best animation js library anime.js Vs gsap

  • @OneBrokeBloke
    @OneBrokeBloke Před rokem

    Why not just use "let" all the time? The difference is that let can be reassigned, but what consequense does it have to use let and NOT assign it anything, versus having used const to do so? Seems like "Let" is just flexible when you need it to

    • @dcode-software
      @dcode-software  Před rokem +2

      The main thing in my eyes is that it helps better communicate your code. Put it this way, if you see "const" then you KNOW it will never be reassigned. Whereas you know "let" might be a computed variable.