Let’s play… Does your code suck? JavaScript Variables Edition

Поделиться
HTML-код
  • Опубликовано: 22 авг 2024
  • Can you tell which code example is bad? Learn the subtle differences between variables in JavaScript by comparing let vs var.
    Learn more about JS in my full course fireship.io/co...
    #javascript #programming #game

Комментарии • 703

  • @wlockuz4467
    @wlockuz4467 5 месяцев назад +3861

    You had me at "does your code suck".
    Yes it does.

    • @mesihburgaz8637
      @mesihburgaz8637 5 месяцев назад +3

      if you don't know than say it so i can skip you

    • @LuisSierra42
      @LuisSierra42 5 месяцев назад +23

      This is the sign of true maturity in software engineering

    • @orterves
      @orterves 5 месяцев назад +11

      I gave it a 50/50 till he followed up with JavaScript. Then 100% yes.

    • @justarandomguy6794
      @justarandomguy6794 5 месяцев назад +3

      But if you know it sucks then you are better than half of the coders

    • @JeremyAndersonBoise
      @JeremyAndersonBoise 5 месяцев назад +5

      Hired.

  • @TehKarmalizer
    @TehKarmalizer 5 месяцев назад +3303

    I mostly watch JS videos like this to continue validating why I don’t do web development.

    • @spunzel851
      @spunzel851 5 месяцев назад +50

      Then what do you do ?

    • @TehKarmalizer
      @TehKarmalizer 5 месяцев назад

      @@spunzel851 internal desktop and CLI tools development, mostly.

    • @migvelv
      @migvelv 5 месяцев назад +12

      Same 😂

    • @hikari1690
      @hikari1690 5 месяцев назад +105

      But web dev is fun. Though I can't seem to get hired

    • @adam422
      @adam422 5 месяцев назад +21

      ​@@hikari1690where are you located?

  • @tomasmartinez6726
    @tomasmartinez6726 5 месяцев назад +829

    I've avoided using var without knowing what it does, but this really helped me understand, thanks!

    • @CottidaeSEA
      @CottidaeSEA 5 месяцев назад +60

      This is not the only reason why it's awful. It also has some real awful scoping issues.

    • @michawhite7613
      @michawhite7613 5 месяцев назад +11

      ​@@CottidaeSEA I think the scoping issue is what the video was talking about

    • @CottidaeSEA
      @CottidaeSEA 5 месяцев назад

      @@michawhite7613 It was only about one of the scoping issues.

    • @j1000a
      @j1000a 5 месяцев назад +41

      Use const until you absolutely can't.

    • @CottidaeSEA
      @CottidaeSEA 5 месяцев назад +2

      @@michawhite7613 Unsure if I just can't see my reply, but basically, the video doesn't go into all of the scoping issues.

  • @mylesbuckley9675
    @mylesbuckley9675 5 месяцев назад +250

    Gotta love getting a runtime error for something which can be statically checked.

    • @arnerademacker
      @arnerademacker 5 месяцев назад +16

      That's just interpreted languages though?

    • @Templarfreak
      @Templarfreak 5 месяцев назад +14

      @@arnerademacker yeah, it's an unfortunate but necessary evil in order to have all the other niceties that runtime interpreted languages have.

    • @arobie92
      @arobie92 5 месяцев назад +6

      @@Templarfreak What kind of niceties do you have in mind? Most of the ones I can think of aren't necessarily tied to interpreted languages, but I'm very possibly forgetting some.

    • @Templarfreak
      @Templarfreak 5 месяцев назад +1

      @@arobie92 nothing is tied explicitly to any particular interpreted language, no, but that's because any language can be runtime interpreted if you are ballsy and brave enough. at which point, any language can have the benefits of doing so. you get advantages like VERY fast feedback, possibly even basically instant if you can reload the code without needing to reload an entire program.

    • @arobie92
      @arobie92 5 месяцев назад +1

      @@TemplarfreakAh so the primary benefit you're getting at is a managed runtime? I'll definitely agree that hot reloading of modules, while technically doable in compiled code, is significantly easier in managed languages.

  • @stevenclark2188
    @stevenclark2188 5 месяцев назад +257

    As a C/C++ guy that's a big "Holy shit people live like this?!" thing.

    • @12Fakeaccount
      @12Fakeaccount 5 месяцев назад +14

      Tbf, I could say the same about declaring the var typeOf on init. Or having to allocate memory. You and I live on strange worlds, but the other is far stranger.

    • @RealNaisuCinema
      @RealNaisuCinema 2 месяца назад +3

      No, we just don’t use var lol. I’d much rather this than C/C++ 🤢

    • @Faizan29353
      @Faizan29353 Месяц назад

      @@12Fakeaccount you don't need to allocate memory always
      its when you want more control over it that you do
      C/C++ really allow you to access/fu*k up, lower levels of the system
      you can divide by 0 and it continues the program for ever (Alhtough compilers and windows can now catch it)
      both have their uses
      JS for web
      C for Win native applications etc

    • @aleixroca1988
      @aleixroca1988 Месяц назад +28

      ​@@RealNaisuCinema C/C++ makes you a powerful wizard though

    • @cyber3371
      @cyber3371 28 дней назад +1

      Fr

  • @evanbelcher
    @evanbelcher 5 месяцев назад +88

    One of the most important lessons I learned early in my career as a SWE was that exceptions are good. The way they were taught in college, I felt like my job was to make sure nothing ever threw an exception and halted so I ended up with try/catches and log messages everywhere. No: if something goes wrong, you want to throw a good exception and let it break

    • @skyhappy
      @skyhappy 5 месяцев назад +1

      When do you decide to not let it break?
      Also do you think that the software education you got in college was poorly taught?
      And did the professors usually have no industry experience?

    • @rafaelmesaglio1399
      @rafaelmesaglio1399 5 месяцев назад +7

      ​@@skyhappyyou don't let the code break when there's scenarios in which you know it's gonna break so you want to control what happens after the errors come knocking. That's why it's called error handling, blindly catching any and all errors is just a debug nightmare

    • @rafaelmesaglio1399
      @rafaelmesaglio1399 5 месяцев назад +2

      If you're going into development you'll eventually deal with some application that has a server, and many clients.
      In this scenario you'll have to make everybody talk to eachother, and it's not about if, it's about when a connection error will happen.
      At that point based on the reason of the error happening you might want to have the code try again, notify the user and ask them to check their connection, or kindly tell them that your app is facing some challenge and they should come back at another time

  • @echoarts3366
    @echoarts3366 5 месяцев назад +463

    My personal go-to: use "const" for everything unless you need to mutate/set the value - then use let; even then consider using a new const if you can. Don't touch var like it's got an infection, I can't remember the last time I had to use it.

    • @Minty_Meeo
      @Minty_Meeo 5 месяцев назад +11

      I wish more C/C++ writers were const correct whenever possible.

    • @adityaanuragi6916
      @adityaanuragi6916 5 месяцев назад +34

      Unless you need to mutate?
      You can mutate arrays and objects even if they are const,
      const arr = [10,20]
      arr.push(30) works

    • @bgdgdgdf4488
      @bgdgdgdf4488 5 месяцев назад +53

      ​@@adityaanuragi6916just becaude you can, doesn't mean you should. Const keyword tells something to the code reader.

    • @erickmoya1401
      @erickmoya1401 5 месяцев назад +20

      This. Like kids game. You ever write var you die. Never ever do it.

    • @yueguifan
      @yueguifan 5 месяцев назад +14

      Rust programmers be like

  • @DK-ox7ze
    @DK-ox7ze 5 месяцев назад +70

    Ah, the good old days of tricky js interview questions.

    • @ninhdang1106
      @ninhdang1106 5 месяцев назад +7

      It’s still used for entry level interview. I remember having a hard time explaining “why var sucks” just because I proactively chose not to use it lol

    • @ollivainionpaa684
      @ollivainionpaa684 5 месяцев назад +3

      Yes very tricky. Using variable before defining it. Would just spit on the face, laugh and leave if that wouldn't be the sought answer.

    • @Aestareth_
      @Aestareth_ 2 месяца назад

      that is not tricky lol. most js interview questions are harder than this

  • @FloWoelki
    @FloWoelki 5 месяцев назад +25

    i love to use const first and then adjust later with let, if needed (like in Rust, having immutability first and then adjust).

    • @Dylan_thebrand_slayer_Mulveiny
      @Dylan_thebrand_slayer_Mulveiny 5 месяцев назад +1

      You can't override a const. Const means constant. As in cannot change. You have no idea what you're talking about.

    • @FloWoelki
      @FloWoelki 5 месяцев назад +8

      ​@@Dylan_thebrand_slayer_Mulveiny i never said that i can override const :D i've just said that i would use const first, and adjust later with let.

    • @saltech2024
      @saltech2024 4 дня назад

      Well try this:
      For placeholder variables like arr, obj etc use let because along the way they'll be updated
      const for like loops or callbacks fxns

  • @andreujuanc
    @andreujuanc 5 месяцев назад +41

    I can't tell because I can barely see the screen when RUclips puts buttons, labels, and other bs all around and blocks everything.

    • @redrush-hp9li
      @redrush-hp9li 5 месяцев назад

      How small is ur phone?

    • @andreujuanc
      @andreujuanc 5 месяцев назад +6

      @@redrush-hp9li size is not important

    • @mastermind4193
      @mastermind4193 5 месяцев назад +3

      @@andreujuanc tell this to your GF

    • @eadwacer524
      @eadwacer524 5 месяцев назад +1

      Someday the video will just be an animated background for a grid of buttons.

    • @user-ed1nw6vr8n
      @user-ed1nw6vr8n 4 месяца назад +1

      i have the same problem both on the phone and on the computer

  • @cinderwolf32
    @cinderwolf32 5 месяцев назад +19

    "does your code suck"
    I fixed a display issue the other day by adding a 0ms setTimeout.

    • @CFEF44AB1399978B0011
      @CFEF44AB1399978B0011 4 месяца назад +1

      Technically that actually does delay your code a bit. I'm not sure if it's a microtask or having it to somewhere else in the queue. But there is a whole set of things that occur when you set timeout to zero and promise and immediately resolved it. Those like an entire algorithm for how to handle those things

    • @zedpoutine
      @zedpoutine 2 месяца назад

      I once fixed buggy code at a new job. Previous Dev tried to fix issues by using multiple timeouts. Page ended up loading 3 seconds faster. I got a 13k$ bonus that year. :)
      So I guess I have to thank guys like you.

    • @Stone_624
      @Stone_624 Месяц назад

      "I have no idea WHY this works, But it does, So just don't touch it"

    • @Lumither-404
      @Lumither-404 28 дней назад

      So basically running code in new thread ?

    • @zedpoutine
      @zedpoutine 28 дней назад

      @@Lumither-404 There is only one thread in a browser. Using setTimeout will put its callback function in the event loop stack to be called later. Sometimes this delay is sufficient for code this callback function depends on to be evaluated. Search for "Race condition in JavaScript".

  • @micheledelzoppo13
    @micheledelzoppo13 5 месяцев назад +41

    Thanks for letting me know before I end up messing up in the future 😅

    • @squidy2902
      @squidy2902 5 месяцев назад +7

      just never use var, i've never found a reason to use it.

    • @LosFarmosCTL
      @LosFarmosCTL 5 месяцев назад

      @@squidy2902yup there is no legitimate reason to use it, if anyone at any point tells you that there is, they are wrong 😂

    • @MrRagday
      @MrRagday 5 месяцев назад

      Var and future)))

    • @clerpington_the_fifth
      @clerpington_the_fifth 4 месяца назад

      don't worry you'll still mess up, all is well : D

  • @AnastasiyaSoyka
    @AnastasiyaSoyka 5 месяцев назад +62

    Praise Cthulhu, and his favorite programming language, JavaScript.

    • @Templarfreak
      @Templarfreak 5 месяцев назад +1

      ah that makes sense. this feature probably only works for a being such as Cthulhu who doesnt care about the constraints of spacetime at all.

  • @pugz3230
    @pugz3230 5 месяцев назад +7

    No, my code does not suck. Javascript does.

  • @BlueBearOne
    @BlueBearOne 2 месяца назад +1

    I respect and greatly appreciate your work so much. I'd love to have a countless number of these as I start my journey into JavaScript. Either way, THANK YOU!

  • @ultragigachader
    @ultragigachader 5 месяцев назад +6

    Good one, I knew the var would hoist but I didn't know the value assignment would be executed after the log. I think even with a 100 years of JS experience one can be surprised from time to time.

  • @kebien6020
    @kebien6020 5 месяцев назад +18

    The TDZ is temporal, as opposed to scope-based. i.e. You can use your variable before it's defined in code order, as long as by the _time_ hou need it, it's been defined.
    function logX() {
    console.log(x)
    // ☝️ refers to the x below thanks to hoisting
    }
    let x = 15
    logX() // prints 15 just fine

    • @LosFarmosCTL
      @LosFarmosCTL 5 месяцев назад +7

      one javascript snippet a day keeps the motivation to do webdev away 😭 wth is that shit how can a closure capture a variable before it is defined (i know you explained why but who tf though it’s a good idea lmao)

    • @isometric_shahil
      @isometric_shahil 5 месяцев назад

      That's very interesting, thanks for sharing this

    • @adam7802
      @adam7802 5 месяцев назад

      @@LosFarmosCTL Thankfully scoped variables and arrow functions exist so you can just pretend this doesn't.

    • @kebien6020
      @kebien6020 5 месяцев назад +2

      @@adam7802 You're misunderstanding. This applies _specifically_ to scoped variables (TDZ only applies for let and const variables). And it's _more_ relevant if you use arrow functions. e.g.
      console.log(plus(5, 3)) // prints 8
      function plus(a, b) {
      return a + b
      }
      Compare to:
      console.log(plus(5, 3)) // TDZ error
      const f = () => console.log(plus(5, 3))
      const plus = (a, b) => a + b
      f() // works fine

    • @adam7802
      @adam7802 5 месяцев назад

      @@kebien6020 I meant more in general rather than this specific issue. Although I didn't know that would work... Javascript is such a mess.

  • @deepaksurya9742
    @deepaksurya9742 5 месяцев назад +5

    The error is not 'a is not defined' it will be ' can not access a before initialisation '

  • @MichaelSt
    @MichaelSt 5 месяцев назад +63

    It’s not the code that sucks at this point it’s JavaScript itself

    • @NorthLaker
      @NorthLaker 5 месяцев назад +8

      It's the necessity for backwards compatibility that makes it suck. Programmers just didn't know how to write clean code back in the early days :)

    • @additionaddict5524
      @additionaddict5524 5 месяцев назад +2

      have a decent linter and you'll stick to a subset of js that doesn't suck

    • @divinecomedian2
      @divinecomedian2 5 месяцев назад

      Always has been

    • @innesiparacheirodon1140
      @innesiparacheirodon1140 5 месяцев назад

      What do you mean ? the code is non-sense but JavaScript handled it quite well throwing reasonable output.

    • @RealFlicke
      @RealFlicke 5 месяцев назад +1

      It's bad, but I had a C++ class and it felt like 80% of the language is forbidden territory.

  • @frontend3409
    @frontend3409 5 месяцев назад +4

    2005 called and he wanted his var back

  • @emrescript
    @emrescript 5 месяцев назад +40

    currently this comment section is the only thing that is worse than var.
    On second thought-

  • @ped5392
    @ped5392 Месяц назад

    Not me realising this was the error I spent several hours on a couple of months ago (and gave up on).
    Thanks Fireship, very cool.

  • @jorionedwards
    @jorionedwards 5 месяцев назад +5

    I know nothing about javascript and just guessed that var does something funky based on my minimal Rust experience.

  • @salmanazam9444
    @salmanazam9444 4 месяца назад +2

    I started learning JS a few months ago and initially would only use var. I thought it was very convenient to make everything of global scope. But I stopped using it completely in a month or two because I realized its actually more convenient to have variables only take local scope.
    Been using const almost exclusively since then.
    Btw, I like JS. I liked it from the start. Yes, its very messy and you get the impression that it got more features without being made 'neater', but its really versatile and powerful. And yes, my code does suck. I make things too difficult. Whatever practice/learning I'm supposed to do, I think of some way I can make it ten times more complex, just to do some extra stuff.

    • @skylo706
      @skylo706 4 месяца назад +1

      Thats the way my friend. We all had this journey until we get to know stuff better ^^ In coding, skill comes with experience

  • @TechnoSan09
    @TechnoSan09 2 месяца назад +1

    Totally quitting var keyword and using typescript is one of the best decision in my life

  • @UnrealOG137
    @UnrealOG137 5 месяцев назад

    I learned about hoisting variables in my compilers class. This is a really good explanation!

  • @somedooby
    @somedooby 2 месяца назад

    I'm not quite a js dev, but I might be coding js soon and definitely needed to know this

  • @chbrules
    @chbrules 5 месяцев назад +15

    Us C devs know to always declare and define your variables before you use them.

    • @PlanetComputer
      @PlanetComputer 5 месяцев назад +1

      gotta start doing that for pointers too man

    • @Zapnl
      @Zapnl 5 месяцев назад +1

      Yea sure, but if your code changes later you might miss a spot a variable is used - which should result in a compile error , but seems like JS is just 'fine' with it.

    • @Rocco-tb9ih
      @Rocco-tb9ih 5 месяцев назад +1

      I've always put the declaration first and I don't typically use languages that care. It just feels wrong, like using someone's name before they've introduced themselves lmao

  • @CascadiaNow69
    @CascadiaNow69 3 месяца назад +1

    Aha!! I got it right! I’ve been studying JavaScript for like 7 hours total! I am so fucking smart!!!

  • @theilluminatimember8896
    @theilluminatimember8896 5 месяцев назад +13

    I always use let ever since it became popular, but now I see why it got popular. I probably don't even realize how many headaces I've dodged

    • @MrRagday
      @MrRagday 5 месяцев назад

      Not many actually. You just avoid 1 concept

  • @h051n
    @h051n 5 месяцев назад

    First time i actually already knew this and actually understood what you were talking about!

  • @blauesaxolotl
    @blauesaxolotl 22 дня назад +1

    Does your code suck ❌️
    Does your programming language suck ✅️

  • @hiki2853
    @hiki2853 5 месяцев назад +1

    nice, I knew about the var hoisting thing but didn't know that the values didn't get hoisted along. makes sense why they updated it

    • @MrRagday
      @MrRagday 5 месяцев назад

      You cannot get value before you assigned it. Common sense.

  • @davidjohnston4240
    @davidjohnston4240 19 дней назад

    Using "let" when programming makes me feel like I'm back in the late 70s programming in BASIC.

  • @lutf_azn
    @lutf_azn Месяц назад

    Need more of this content

  • @Electricz0
    @Electricz0 18 дней назад

    Python does hoisting, too, and you can't turn it off. I'm actually really happy I knew this.

  • @whoman0385
    @whoman0385 5 месяцев назад +11

    what are these comments man 🙏

  • @parkourninja21
    @parkourninja21 3 месяца назад

    This is my drug. Like a continuation of my computer systems class where I first learned how scoping works on a hardware level

  • @thedid37
    @thedid37 5 месяцев назад

    "Temporal Death Zone"; fucker got me with that Loki suff

  • @KaramAlayan
    @KaramAlayan 5 месяцев назад +2

    Brother this isnt "does your code suck"
    Its "does Javascript suck ?"
    And ill be proud to answer YES YES IT SUCKS

    • @MrRagday
      @MrRagday 5 месяцев назад

      Seems like you know almost nothing about js, am i right?

  • @loktar00
    @loktar00 5 месяцев назад +2

    No one uses var anymore anyway there's nothing it provides over let or const to justify it's usage.

  • @Chilaxolotl
    @Chilaxolotl Месяц назад

    Functions also get hoisted, but only if declared with the function keyword.

  • @GottZ
    @GottZ 5 месяцев назад

    nice! I passed. I was immediately like.. oh that's undefined!

  • @madskaddie
    @madskaddie 5 месяцев назад +1

    a general rule, scopewise, const > let > var > global.
    but var and global do have their use cases.
    the example is so simple that const is the "right answer" and both samples "suck" 😜

  • @howdarethee
    @howdarethee 5 месяцев назад

    Finally I LEARNT what the difference is

  • @3limin4t0r
    @3limin4t0r Месяц назад

    Fun fact. "let" variables also get hoisted, but you cannot access them before they are assigned a value. If you would define a function using "a", then define "let a = 1", and then call the function - no exception is thrown.

  • @99temporal
    @99temporal 5 месяцев назад

    This one was easy peasy... I come from a time where there was no let and const, only var... So those quirks are basically ingrained in my soul now
    JavaScript used to suck so bad

  • @KarlLew
    @KarlLew 5 месяцев назад

    Lol. Thanks for articulating why I stopped using var. I got hoisted too much for my liking and tossed that out a while back.

  • @4thirteenYT
    @4thirteenYT 5 месяцев назад

    " that can easily debug" get me😅

  • @flapjacksmike
    @flapjacksmike 5 месяцев назад

    What a great word. Hoiiiiiii-sted.. Love it. I actually ran into this issue yesterday. 😆

  • @thederpydude2088
    @thederpydude2088 2 месяца назад

    I've never called myself an experienced programmer, but I guess my recent browsing through JS documentation paid off because I was surprisingly able to figure out what the code would do lol

  • @randomdamian
    @randomdamian 5 месяцев назад

    I learned something today... I knew that let would throw an error, but didn't knew about the var throwing the declaration to the top and the reassigning it on the spot.

  • @APerson-14
    @APerson-14 27 дней назад +1

    Good to know this.
    I knew it was B
    Simply because var is automatically stupid

  • @Lord_Omni
    @Lord_Omni 5 месяцев назад

    Long long time ago there was no let in JS, and everything was normal. Now you have choise that causes different behaviors. It took a long while to shift myself from var to let, but because C# still uses var just like JS now uses let...

  • @harsh.vision
    @harsh.vision 5 месяцев назад +1

    Hoisting is important in jetpack compose in Native Android

  • @itjustcrashed
    @itjustcrashed 2 месяца назад +1

    Bruh swift is like: THE ERROR IS *RIGHT THERE* do you SEE IT???!!!!!???!?!?!??!!!???

  • @dinoeebastian
    @dinoeebastian 4 месяца назад

    I know next to nothing about Javascript, so at first I was shocked when it said the first one had an error since that was the one I picked, made a lot more sense when I turned out to be wrong

  • @johnbrooks7350
    @johnbrooks7350 5 месяцев назад +1

    Ya know… when I hear JS being a trash fire of weird language mechanics, I used to think they were exaggerating.

  • @TheeSirRandom
    @TheeSirRandom Месяц назад

    Started learning JS just 2 days ago, and I never really knew why everyone was saying not to use var to set variables. It seems much more telling in its name, so you would think its better. Good to know I guess.

  • @bawbsmith
    @bawbsmith 5 месяцев назад +1

    Ngl the RUclips shorts interface is shit. I didn’t realize the difference cuz “var” was partially covered, and there’s no way to hide the buttons over the video

  • @unn06
    @unn06 Месяц назад

    This is cool. I know JS and understand hoisting. I just subconsciously never use 'var' and instead use 'let' or 'const' depending on what I need.

  • @mpty2022
    @mpty2022 5 месяцев назад +1

    the bottom part, cant really read anything because of this great gui by youtube covering about 60% of the acreen

  • @Roboprogs
    @Roboprogs 5 месяцев назад

    The “const” keyword made an impression on me, but “let” (vs “var”) never really did.
    So, my code does suck. And both examples in the video are still broken.
    Thanks for pointing out the error diagnostic differences, though. The “Block scope” (in giant oversized functions???) aspect of “let” never mattered much to me, as someone who did a lot of Pascal, and some Lisp, etc, back in uni in the 80s, dragged into C and its bastard spawn in the 90s.

    • @Roboprogs
      @Roboprogs 5 месяцев назад

      And I would rather do Clojurescript than Typescript, but rather still have a dependency on neither. Bah, humbug! 😁

  • @idontknowanygoodnames1498
    @idontknowanygoodnames1498 Месяц назад

    When a language is less consistent and more confusing than literal undefined behaviour, you know you've messed up somewhere.

  • @olhoTron
    @olhoTron Месяц назад

    Not really "after the declaration" but "after the declaration has run"
    If you have a function above the declaration but it only gets called after the declaration, it works fine

  • @joakimvillo3411
    @joakimvillo3411 9 дней назад

    Saw var, instantly knew the answer

  • @a.j.outlaster1222
    @a.j.outlaster1222 2 месяца назад

    I was thinking, "Hm, Error?
    But isn't that what's supposed to happen?...
    Hmm..."

  • @akulgoel9259
    @akulgoel9259 3 месяца назад +1

    "does your code suc-"
    yes it does

  • @Skimmy404
    @Skimmy404 5 месяцев назад

    I was right! I guessed the bottom one. I'm still a coding beginner, and I didn't know about the hoisting. Good to know!

    • @MrRagday
      @MrRagday 5 месяцев назад

      Not needed there is no var in modern js development

  • @casev799
    @casev799 5 месяцев назад

    I just define everything I know I use right at the top, even abouve (and outside, obviously) functions, until they need to be changed

  • @siteantipas6837
    @siteantipas6837 5 месяцев назад +1

    One shouldn't even use "var" anymore. The keyword "let" is more cool.

  • @wartyrant8627
    @wartyrant8627 5 месяцев назад

    The Price is Right theme still bumps

  • @arunsp767
    @arunsp767 5 месяцев назад +1

    Nah I'm good. I have never in my life expected a variable to hold a value before declaring it

  • @sadjadasadi4575
    @sadjadasadi4575 5 месяцев назад +1

    That's why it's always suggested to either use let and const

  • @skylo706
    @skylo706 4 месяца назад

    I like and doslile js at the same time. It's easy but it also lets a lot of no go stuff go through until it breaks at some point.

  • @jinzotun
    @jinzotun 5 месяцев назад

    We need more videos like this .

    • @MrRagday
      @MrRagday 5 месяцев назад

      You want to get knowledge about 10 years ago js?

  • @darthtorus9341
    @darthtorus9341 3 месяца назад

    This is why I've started to use let instead of var whenever I'm coding in JS.

  • @dipereira0123
    @dipereira0123 5 месяцев назад

    "Does your code Suck?" You ask, but you already had the answer when you said "Javascript edition"

  • @ShadowOverflow
    @ShadowOverflow 5 месяцев назад

    YOU JUST SAVED ME HOURS.

  • @deyjaacterius9610
    @deyjaacterius9610 5 месяцев назад

    I love JavaScript because windows is my daily driver and discovering little weird hacks and quirks of the language reminds me of getting windows to work and also horse-climbing mountains in Skyrim.

  • @Terra_135
    @Terra_135 5 месяцев назад

    finally a js developer who doesnt root for silent errors

  • @umjames
    @umjames 4 месяца назад

    Idea for new game show: This Code Isn't Right. Keep the same music from The Price is Right

  • @Gamertrip4life
    @Gamertrip4life Месяц назад

    I knew which one was bad because of lint :) But I didn't know why!

  • @badgercode
    @badgercode 2 месяца назад

    I had a fun issue where someone used "var" in a for loop for the iterator variable.
    For some wild reason, some code outside of the loop also tried to use the iterator variable.
    Then, the code editor changed a bunch of vars to lets and everything broke 🙃

  • @amitavasengupta5580
    @amitavasengupta5580 4 месяца назад

    When in doubt, use const.

  • @tacticalassaultanteater9678
    @tacticalassaultanteater9678 5 месяцев назад +1

    There's a very annoying class of JavaScript developers who internalized the lack of errors and will insist that the fewer incorrect code samples produce errors, and the later those errors surface, the better.

  • @RandomAccessGuy
    @RandomAccessGuy 5 месяцев назад

    that log before the variable is making my java brain hurt

  • @justsomebeanz
    @justsomebeanz 5 месяцев назад

    And here I was thinking that bar just means scoped variable

  • @averagewhatdude
    @averagewhatdude 4 месяца назад

    Dayum I just started to learn coding and I'm already full of coding shorts, I'm happy tho i don't understand 90% of them aha.

  • @willb.r2055
    @willb.r2055 19 дней назад

    when I see a JavaScript code with var statements all over it I run from it as fast as I can 😂

  • @nunchukGun
    @nunchukGun 5 месяцев назад

    This explains the time i fixed something by switching let to var 😂

  • @ouwyukha
    @ouwyukha 5 месяцев назад +1

    you can rename to Let's Play: Do you use ESLINT

  • @madmartigan1634
    @madmartigan1634 5 месяцев назад

    Oh cool. I only stopped hoisting to assuage linting rules, nice to know there's an actual reason.

    • @lgasc
      @lgasc 5 месяцев назад

      Every lint rule has a reason behind it.

  • @stysan
    @stysan 2 месяца назад

    you can still debug the undefined thing (at least in Firefox, I don't use chrome)

  • @1wasavi
    @1wasavi 5 месяцев назад

    im happy I actually knew that felt wrong, just dodnt know why

  • @HhddGufif
    @HhddGufif 9 дней назад

    Chatgpt told me this the other day and I thought it was hallucinating

  • @afraidofmoths6547
    @afraidofmoths6547 4 месяца назад

    Temporal dead zone is kind of a sick name

  • @stazchristo
    @stazchristo 28 дней назад

    I guess you just found us a use case for var, since I have been avoiding it ever since let and const came out.

  • @GetFitEatRight
    @GetFitEatRight 5 месяцев назад

    Fuck... I got baited. Nice work my man. I'm all like the top one the top one.

  • @thatJackBidenTalksAbout
    @thatJackBidenTalksAbout 5 месяцев назад

    JavaScript's lava flow quirks are what make it fun. Especially compared to C++, where template metaprogramming has made everything just...just awful.