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

Поделиться
HTML-код
  • Опубликовано: 24 фев 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/courses/js/
    #javascript #programming #game
  • НаукаНаука

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

  • @wlockuz4467
    @wlockuz4467 4 месяца назад +2955

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

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

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

    • @LuisSierra42
      @LuisSierra42 4 месяца назад +17

      This is the sign of true maturity in software engineering

    • @orterves
      @orterves 4 месяца назад +7

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

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

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

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

      Hired.

  • @TehKarmalizer
    @TehKarmalizer 4 месяца назад +2831

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

    • @spunzel851
      @spunzel851 4 месяца назад +43

      Then what do you do ?

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

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

    • @migvelv
      @migvelv 4 месяца назад +11

      Same 😂

    • @hikari1690
      @hikari1690 4 месяца назад +89

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

    • @adam422
      @adam422 4 месяца назад +19

      ​@@hikari1690where are you located?

  • @tomasmartinez6726
    @tomasmartinez6726 4 месяца назад +688

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

    • @CottidaeSEA
      @CottidaeSEA 4 месяца назад +55

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

    • @michawhite7613
      @michawhite7613 4 месяца назад +9

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

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

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

    • @j1000a
      @j1000a 4 месяца назад +36

      Use const until you absolutely can't.

    • @CottidaeSEA
      @CottidaeSEA 4 месяца назад +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 4 месяца назад +171

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

    • @arnerademacker
      @arnerademacker 4 месяца назад +10

      That's just interpreted languages though?

    • @Templarfreak
      @Templarfreak 4 месяца назад +10

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

    • @arobie92
      @arobie92 4 месяца назад +3

      @@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 4 месяца назад +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 4 месяца назад +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.

  • @evanbelcher
    @evanbelcher 4 месяца назад +59

    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 4 месяца назад +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 4 месяца назад +5

      ​@@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 4 месяца назад +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 4 месяца назад +436

    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 4 месяца назад +9

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

    • @adityaanuragi6916
      @adityaanuragi6916 4 месяца назад +32

      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 4 месяца назад +47

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

    • @erickmoya1401
      @erickmoya1401 4 месяца назад +18

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

    • @yueguifan
      @yueguifan 4 месяца назад +13

      Rust programmers be like

  • @DK-ox7ze
    @DK-ox7ze 4 месяца назад +62

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

    • @ninhdang1106
      @ninhdang1106 4 месяца назад +6

      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 4 месяца назад +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_ Месяц назад

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

  • @stevenclark2188
    @stevenclark2188 4 месяца назад +18

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

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

      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 Месяц назад +1

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

    • @Faizan29353
      @Faizan29353 17 дней назад

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

  • @FloWoelki
    @FloWoelki 4 месяца назад +21

    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 4 месяца назад +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 4 месяца назад +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.

  • @cinderwolf32
    @cinderwolf32 4 месяца назад +12

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

    • @CFEF44AB1399978B0011
      @CFEF44AB1399978B0011 3 месяца назад +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 23 дня назад

      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 9 дней назад

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

  • @andreujuanc
    @andreujuanc 4 месяца назад +34

    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 4 месяца назад

      How small is ur phone?

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

      @@redrush-hp9li size is not important

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

      @@andreujuanc tell this to your GF

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

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

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

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

  • @micheledelzoppo13
    @micheledelzoppo13 4 месяца назад +40

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

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

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

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

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

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

      Var and future)))

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

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

  • @theilluminatimember8896
    @theilluminatimember8896 4 месяца назад +12

    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 4 месяца назад

      Not many actually. You just avoid 1 concept

  • @AnastasiyaSoyka
    @AnastasiyaSoyka 4 месяца назад +58

    Praise Cthulhu, and his favorite programming language, JavaScript.

    • @Templarfreak
      @Templarfreak 4 месяца назад +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.

  • @ultragigachader
    @ultragigachader 4 месяца назад +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.

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

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

  • @kebien6020
    @kebien6020 4 месяца назад +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 4 месяца назад +6

      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 4 месяца назад

      That's very interesting, thanks for sharing this

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

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

    • @kebien6020
      @kebien6020 4 месяца назад +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 4 месяца назад

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

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

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

  • @BlueBearOne
    @BlueBearOne 28 дней назад +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!

  • @MichaelSt
    @MichaelSt 4 месяца назад +61

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

    • @NorthLaker
      @NorthLaker 4 месяца назад +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 4 месяца назад +1

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

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

      Always has been

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

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

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

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

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

    No, my code does not suck. Javascript does.

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

    2005 called and he wanted his var back

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

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

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

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

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

    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

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

    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.

  • @jasonsimpson1609
    @jasonsimpson1609 Месяц назад +15

    Is your code JavaScript? Then it sucks.

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

      How in the living fuck do I make my websites function then?

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

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

  • @hiki2853
    @hiki2853 4 месяца назад +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 4 месяца назад

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

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

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

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

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

  • @salmanazam9444
    @salmanazam9444 3 месяца назад +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 2 месяца назад +1

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

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

    what are these comments man 🙏

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

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

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

    Hoisting is important in jetpack compose in Native Android

  • @Chilaxolotl
    @Chilaxolotl 10 дней назад

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

  • @chbrules
    @chbrules 4 месяца назад +14

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

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

      gotta start doing that for pointers too man

    • @Zapnl
      @Zapnl 4 месяца назад +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 4 месяца назад +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

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

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

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

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

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

    " that can easily debug" get me😅

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

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

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

    The Price is Right theme still bumps

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

    And here I was thinking that bar just means scoped variable

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

    "does your code suc-"
    yes it does

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

    YOU JUST SAVED ME HOURS.

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

    I remember we had this exact question on a programming exam in high school

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

    that log before the variable is making my java brain hurt

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

    Finally I LEARNT what the difference is

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

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

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

    I just realized that I completely forgot why my hoisted code is working

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

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

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

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

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

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

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

    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 4 месяца назад

      Not needed there is no var in modern js development

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

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

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

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

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

    It's amazing that undefined is a defined value

  • @newshyne
    @newshyne Месяц назад +1

    And you also have to write "use strict".

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

    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 🙃

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

    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.

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

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

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

    We need more videos like this .

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

      You want to get knowledge about 10 years ago js?

  • @Gamertrip4life
    @Gamertrip4life 13 дней назад

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

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

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

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

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

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

    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

  • @madskaddie
    @madskaddie 4 месяца назад +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" 😜

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

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

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

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

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

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

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

    Except for the part where javascript errors occur only at run time, so if that code is rarely executed, its gonna be a pain to fix

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

    love how you can bundle a totally nerd fact into a meme game youtube short

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

    I was confused why B was not throwing a error 😂😂😂

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

    When in doubt, use const.

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

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

  • @stysan
    @stysan 26 дней назад

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

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

    This is why I do all my low-level stuff in scratch

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

    Temporal dead zone is kind of a sick name

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

    Nice editing 😂

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

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

  • @3limin4t0r
    @3limin4t0r 16 дней назад

    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.

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

    That's why I try not to use mutations unless I absolutely have to

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

    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

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

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

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

      Every lint rule has a reason behind it.

  • @Claude_Developer
    @Claude_Developer 5 дней назад

    I like this

  • @TheeSirRandom
    @TheeSirRandom 16 дней назад

    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.

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

    Oof I knew it hoisted but I didn't know it dropped the value that's wild.😅

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

    That's what he meant. Makes sense.

  • @olhoTron
    @olhoTron 20 дней назад

    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

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

    my code does suck but now I can just prompt the chat app on any modern website with my code and a request to "make it such less", and like magic my code goes from functionally terrible to properly useless.
    What a time to be alive.

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

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

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

    i cant see the second code because of the shorts text lol and now im struggling to send this message because the message button dissapeared. I love yt

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

    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.

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

    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 4 месяца назад

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

  • @unn06
    @unn06 23 часа назад

    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.

  • @Spencer-wc6ew
    @Spencer-wc6ew 4 месяца назад +1

    What is confusing about a not being 1 before "a = 1"!

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

    I was today years old when I learned that.

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

    Nowaday, I build the logic and write the code with python and then translate them into JavaScript using gpt-4.

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

    that is so incredibly cursed.

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

    the error itself sucks : 'a is not defined' yet the language itself has an 'undefined' value which basically means the variable is not defined

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

      console.log(x);
      Uncaught ReferenceError: x is not defined
      console.log(window.x);
      undefined
      When you access global variable through a property access expression it doesn't throw error

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

    Temporal Deadzone 💀 made me laugh for some reason