The Difference Between var and let in JavaScript

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ม.ค. 2025

ความคิดเห็น • 22

  • @polliluiz
    @polliluiz 4 ปีที่แล้ว +2

    I just finished the Getting Started training from Udemy and starting the advanced. Recommended for everyone who is looking for JS training.

  • @ro3843
    @ro3843 2 ปีที่แล้ว

    Thank you for demystifying JavaScript

  • @tanishamatthews2540
    @tanishamatthews2540 4 ปีที่แล้ว +1

    These are such good examples - I am signing up for your advanced classes too! Thank you

  • @ruchirai5775
    @ruchirai5775 4 ปีที่แล้ว

    Every UI developer should see these tutorials!

  • @arunkaiser
    @arunkaiser 5 ปีที่แล้ว +1

    U deserve Best tutor award 👏🏽

  • @TipsforGISChannel
    @TipsforGISChannel 8 ปีที่แล้ว +1

    Thanks for the video. Really helpful.

  • @fredpies
    @fredpies 6 ปีที่แล้ว +1

    very good examples

  • @Luxcium
    @Luxcium 5 ปีที่แล้ว

    Hello 👋 I just want to let you know I have purchased the Advanced JavaScript Class and I am really happy to start my journey. You are really amazing 😉 and I really like what you do. I send you this message as a reminder that const and let are not exotic features of JavaScript. As you know from my previous messages I am kind of in love with JavaScript and all of it’s new features (I should probably become a JS evangelist because it’s a true religion to me) I would like to first say that I respect your experience and I know that you are an old school developer and I am a n00b ... ;-) But I would love you to reconsider using const to remplace let or var everywhere except when you know you will need to reassign the same variable in your code (in fact in your case it could be different because you have small examples to quickly show some functionality) the const keyword should not be confusing if well explained to newcomers (and since you are so good at explaining people will not be confused let me explain) of course it’s probably important first to do the parallel with other language where it would signal immutability obviously in JavaScript it is different... To be able to be comfortable with that special friend the way to understand it and then the way you should probably explain it I think is at first point out that objects are references and that cosnt set a constant reference to the object location in memory and that’s what will not change the key here is the possible optimization in the interpreter if this location in memory is set permanently with const after this is said then that notion of constant is more easy to accept than if pointing first that it’s not useful because you can change your object’s values even using the word const ... Obviously it is super important to mention but by mentioning it first it sets in the mind of newcomers that JavaScript is that weird beast and that everything is illogical with that language... Evidently I was previously just saying “religion” in a metaphorical way and therefore JavaScript is not dogmatic (au contraire) but I would like to see the people who are new to JavaScript being introduced to the const keyword in a way that won’t make it look stranger than he really is ... const to me should be the new var all the time and let should be the exception used for primitive that will need to be reassigned... but it’s my point of view and I hope you will find something useful for your students in flipping around your point of view and paradigm regarding what costs should really mean to JavaScript development (I should do my first post on medium haha it’s long enough to be monetize LoL 😂)

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 ปีที่แล้ว

      You should evangelize on JavaScript! You are correct and I agree with what you say. When I'm following a functional paradigm, I use const a lot more, but old habits die hard. I generally use const for functions as I have no need to change those. I will generally use let for variables, because I come from that flexible world of JavaScript so I like I let says, here is the scope of this variable and it can be changed. If something is global I will use var. That is my personal take on things, but love your input. Keep providing it as I don't have all the answers!!

    • @Luxcium
      @Luxcium 5 ปีที่แล้ว

      All Things JavaScript, LLC with JavaScript many things can be true obviously when moving into TypeScript territory or into the complicated world of linters things stop to be so permissive but let’s pretend for the sake of argument that linters would magically be set to meet up exactly what each programer set of beliefs would be ... then there would be more than one good way (excluding all those rules that are useful only because of the consistency or preferences among a team) what is awesome with JS therefore is what I would like to call his polymorphism (in a general sense not in the specific OOP meaning my linter would’ve been complaining about how I am shadowing a different variable of the same name 🤣 ) the way one could accomplish one same task in many different way and therefore you as a teacher have to express each way and I think according to your philosophie of teaching it’s what you are doing (I assume you want to do like that) therefore you might have to adapt and teach the newer techniques but you have the advantage of being able to teach us people a way that will be better to work on legacy code ... I really like to learn both the new best practices in parallel with the legacy way of thinking that one of your strengths now I am trying to convince you into embracing the new way but not to stop comparing with the other ways (an example would be the rest operator versus the arguments keyword ) anyway it’s 2019 now so it’s been almost 5 years since this new JavaScript I think all of this is not new anymore I really like the way JavaScript (EScript) is now allowed to evolve each year since 2015 when I first learned JS in 98/99 it was not at all the same ecosystem and it was used for onmouseover or onclick events and now with nmp its one of the primary programming language and with CPU capacity nowadays no one is ever talking about the difference between interpreted languages and compiled languages... I think when I first learned it was more like a kid playing with toys now it a grownup man that has remplace a lot of « real » programming languages (exception probably of people writing pilote for hardware or requiring really optimized code)

    • @AllThingsJavaScript
      @AllThingsJavaScript  5 ปีที่แล้ว

      Yes, it is really quite amazing to me how JavaScript has changed over the years. There was a time you could get by with little tidbits in your HTML page. But now you need to truly learn it to use it appropriately.

  • @russelldriver6394
    @russelldriver6394 3 ปีที่แล้ว

    Hi Stephen. I understand let and const are hoisted into the TDZ and allocated seperate memory until initialized and put into a seperate memory block space rather than on the global object. Is this memory space for let and const not accessible in the browser in the same way that var variables can be viewed by expanding the window object? It looks to me like let and const memory is invisible in the browser and you can't go into devtools and look for all your initialized let and const variables? Why is this? Also when typing a let variable into the console that already exists - why does the console know that you are not referencing a variable on window and to look at the block memory?

    • @AllThingsJavaScript
      @AllThingsJavaScript  3 ปีที่แล้ว

      Correct. let and const are not available initialized. As far as reasons, it was intentional in the design of those variable types. As for your question on the console, the console for each browser can behave differently, so the features of the console for a particular browsers (beyond the standard functionality) can be attributed to the browser developer.

  • @dodokwak
    @dodokwak 3 ปีที่แล้ว

    Thank you.

  • @mddawoodrazauddin8841
    @mddawoodrazauddin8841 4 ปีที่แล้ว

    Thanks a lot buddy!

  • @CameronChardukian
    @CameronChardukian 6 ปีที่แล้ว

    Thanks for the simple and easily understood examples.

  • @kprajwal7599
    @kprajwal7599 6 ปีที่แล้ว +1

    best topic

  • @AYMENINFO
    @AYMENINFO 4 ปีที่แล้ว

    thanks sir

  • @seenuvasanv
    @seenuvasanv 7 ปีที่แล้ว +1

    Thanks

  • @ousamaelidrissi5886
    @ousamaelidrissi5886 4 ปีที่แล้ว

    Thanks a lot