Var vs Const vs Let (ES6) - Beau teaches JavaScript

Sdílet
Vložit
  • čas přidán 8. 02. 2017
  • Learn about the difference between const, var, and let in JavaScript ES6 (ECMAScript 6).
    Code
    🔗 codepen.io/beaucarnes/pen/MbMN...
    Other resources on topic:
    🔗 www.jstips.co/en/keyword-var-v...
    🔗 • var, let and const - W...
    Beau Carnes on Twitter: / carnesbeau
    ⭐JavaScript Playlists⭐
    ▶JavaScript Basics: • JavaScript Basics Course
    ▶ES6: • ES6 - Beau teaches Jav...
    ▶Design Patterns: • Design Patterns - Beau...
    ▶Data Structures and Algorithms: • Data Structures and Al...
    ▶Clean Code: • Clean Code - Beau teac...
    -
    We're busy people who learn to code, then practice by building projects for nonprofits. Learn Full-stack JavaScript, build a portfolio, and get great references with our open source community.
    Join our community at freecodecamp.com
    Follow us on twitter: / freecodecamp
    Like us on Facebook: / freecodecamp
    Follow Quincy on Quora: www.quora.com/Quincy-Larson

Komentáře • 57

  • @ylioo
    @ylioo Před 7 lety +77

    This is how you explain it, idk what's up with this 20 min vidoes, let vs var vs const

    • @kotoriitsuka1097
      @kotoriitsuka1097 Před 5 lety +9

      Sometimes it seems like ppl do philosophy...

    • @MCTVARG
      @MCTVARG Před 5 lety +2

      Yeah, we are missing scope a little bit in depth here, what happens when its inside a function as CONST? and as Var? inside an if statement? etc...

    • @Joshua8224
      @Joshua8224 Před 4 lety +1

      check mmtuts video on this. The best!

    • @_runic
      @_runic Před 3 lety

      jesus christ, no kidding. it was hell trying to find this beautiful explanation, i literally only needed to hear the first minute of it to understand.

  • @abhinavkumar8396
    @abhinavkumar8396 Před 3 lety +6

    Best exact ,to the point,explanation. Beautiful.

  • @PratikRatnaparkhi
    @PratikRatnaparkhi Před 7 lety +15

    go beau! go beau! I love this guy!

  • @pratikpokharel5490
    @pratikpokharel5490 Před 3 lety +7

    crisp and clear,covered everything needed less than 4mins.THANKS

  • @rayjaymor8754
    @rayjaymor8754 Před rokem +1

    In less than 4 minutes you explained to me in an easily understandable manner what 30 minute videos and several pages of documentation couldn't get through my skull. Thank you!

  • @aceborja1656
    @aceborja1656 Před 2 lety

    Thank you once again Beau for clarifying.

  • @mikestuff2114
    @mikestuff2114 Před 6 lety +10

    Thank you for keeping it short and to the point.

  • @pleabargain
    @pleabargain Před 7 lety

    Many thanks! Much clearer now!

  • @itzDJ73
    @itzDJ73 Před 2 lety +1

    Very helpful. Thank you!

  • @_runic
    @_runic Před 3 lety +10

    tl;dr
    let - local variables that can be changed
    var - global variables that can be changed
    const - constant variables that cannot be changed

    • @TealDaubs
      @TealDaubs Před rokem +1

      Fucking thank you. Scoured the internet for this answer.

    • @_runic
      @_runic Před rokem

      @@TealDaubs lol never thought this would help anyone

    • @martiananomaly
      @martiananomaly Před rokem

      *tl;dw

    • @_runic
      @_runic Před rokem

      @@martiananomaly no, *tl;dr. look it up

  • @christianrodier3381
    @christianrodier3381 Před 6 lety +1

    That helped a great deal thanks.

  • @theonewhodoesPoland
    @theonewhodoesPoland Před 7 lety +3

    Clear explanations, thanks for sharing!

  • @SamiNami
    @SamiNami Před 7 lety +2

    Thanks

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

    Thanks a lot dude..

  • @ashilshah3376
    @ashilshah3376 Před rokem

    On point thankyou :)

  • @truptisutar2975
    @truptisutar2975 Před 6 lety

    good explanation

  • @batfan1939
    @batfan1939 Před 6 lety +2

    Does this mean we don't need to change or "increment" _i_ anymore? We can use _let_ in loops, and have all of them be _i = foo,_ _i < bar,_ _i++?_

  • @antsanders0893
    @antsanders0893 Před rokem

    Thank you for making this 80 times easier than Codeacademy lol

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

    Thank you!!!!!!!!!!!!!!!!!!!!!

  • @stevenshelby2675
    @stevenshelby2675 Před 4 lety +2

    This guy makes you think you're watching this video at 1.5x speed

  • @sua4443
    @sua4443 Před 6 lety +1

    should you use let instead of var when you can or does it not really matter?

  • @biagio_montelisciani
    @biagio_montelisciani Před 2 lety

    thanks bro

  • @Mikael97
    @Mikael97 Před 2 lety

    Everything is clear to me now. Thanks for explaining the difference between const, let and var.

  • @mirataoskoi5855
    @mirataoskoi5855 Před 6 měsíci

    Guys what do you think I should do : keep learning JS or start working as a content manager for a company?

  • @yanivsalman9685
    @yanivsalman9685 Před 6 lety +1

    you can push to a const variable thats important (:

  • @moza260
    @moza260 Před 3 lety

    ok the var and const is easy thing to remember when first learn, so the let key point is scoop right?

  • @hyunchae2431
    @hyunchae2431 Před 5 lety +1

    without explanation on hoisting, it is not clear why 'var' variable is already available even before it is defined.

    • @rodwinpieterse1950
      @rodwinpieterse1950 Před 3 lety

      It actually is. The JS engine 'hoists' a variable assigned with the var keyword out of the flow before it starts executing synchronously.

  • @p33yush
    @p33yush Před 4 lety

    var also binds itself to window object, but let and const dont do that

  • @khaouladjouabi7270
    @khaouladjouabi7270 Před 4 měsíci

    what is the name of this complier ?

  • @sayantaniguha8519
    @sayantaniguha8519 Před 3 lety

    for(var i=1;i

  • @ashok2484
    @ashok2484 Před 5 lety

    Bro ...what are the basic things are known in js

  • @trappedcat3615
    @trappedcat3615 Před 7 lety +2

    I just use var, closures, and caps to indicate constants. I'll use const and let in 5 years once I don't need to depend on a compiler to interpret them.

    • @BeauCarnes
      @BeauCarnes Před 7 lety +2

      Some people think you should never use var. I wouldn't go that far, though. 😃 medium.com/javascript-scene/javascript-es6-var-let-or-const-ba58b8dcde75#.sn9gfcmp6

    • @trappedcat3615
      @trappedcat3615 Před 7 lety +1

      Beau Carnes I'm looking forward to never using var

  • @zlackbiro
    @zlackbiro Před 5 lety

    If we used code for hack, is that counting as for good, hack++ :D

  • @shrdn2960
    @shrdn2960 Před rokem

    Based.

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

    let: block-lvl VARs - values can be changed
    const: values never change
    var: srsly u don need an explaination for dis:)

  • @sandiladhikari7903
    @sandiladhikari7903 Před rokem

    And if you use for(i = 0; i < 3; i++) without assigning neither let nor var keyword, the i becomes global variable.

  • @debjyotichattopadhyay6679

    watched at 0.5* speed

    • @meru_lpz
      @meru_lpz Před 5 lety

      i can feel you, 0.75 here

    • @oufcena5092
      @oufcena5092 Před 4 lety

      slow CPU? "Human Processing Unit" LOL

  • @unperrier5998
    @unperrier5998 Před 3 lety

    did you know that semicolons are optional? Why bother then?

    • @antoniocastellanos3830
      @antoniocastellanos3830 Před 3 lety

      I’m new but it’s because sometimes they are required so it’s a good habbit to just use them even if they arnt

    • @chexitout
      @chexitout Před 3 lety

      Also most other C based languages do require them, so it's a good habit to get into if you ever end up moving to other languages 👍

    • @unperrier5998
      @unperrier5998 Před 3 lety

      @@chexitout I disagree.
      We should do our best to use the language syntax and idioms.

  • @boriiinglastname8810
    @boriiinglastname8810 Před 5 lety +2

    Ur voice is weird

  • @sua4443
    @sua4443 Před 6 lety

    should you use let instead of var when you can or does it not really matter?