var let const in Javascript Scope | Understanding Global Local Function Block Scope

Поделиться
HTML-код
  • Опубликовано: 22 янв 2025

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

  • @neatunet
    @neatunet 2 года назад +14

    Very detailed perfect lessons you have on your channel! I wish I found your channel earlier because not so many people explain basic foundational things so well. Good work :)

  • @CondeAlberto
    @CondeAlberto 2 года назад +5

    The best explanation of scope I have seen so far.
    It could have avoided me all those "undefined" errors a few weeks ago.
    Very good.

  • @farazk9729
    @farazk9729 2 года назад +2

    Wow! What a thorough explanation. Amazing Dave; by far the best on RUclips.

  • @movierecommendation6667
    @movierecommendation6667 2 года назад

    Sometimes, all you need is a video and it does the work of a whole pdf. Thanks man.

  • @someguy6076
    @someguy6076 6 месяцев назад

    Thanks, Dave !!
    This one came via a link from my lecturer, but I have worked thru a number of your multi-hour videos previously. Your explanations have helped me to understand many of the core concepts of JavaScript programming and web development.

  • @blurrywaters
    @blurrywaters Год назад +2

    Ive been having trouble with scope for the absolute LONGEST, everything else in javascript has made sense except that. The second example at 9:50 was spot on.

  • @bbalot2675
    @bbalot2675 2 года назад

    Thanks Dave! Been looking at several videos on scopes by far the best.

  • @E-business-c3p
    @E-business-c3p 11 месяцев назад

    Roadmap redirected me to your channel, what a tutorial!

  • @VladimirJovana
    @VladimirJovana Год назад

    Can't recommend enough your channel, well thought explanations, concise, thanks a lot for sharing

  • @bekhruzilhomov2599
    @bekhruzilhomov2599 Год назад +1

    Very understandable thanks a lot I liked your video thanks for creating this videos

  • @CineIt
    @CineIt 3 года назад +2

    Amazing explanation. Great work Dave. Thank you.

  • @dr_corrupt1014
    @dr_corrupt1014 Год назад

    this is the best explanation on scope I have ever seen 🎉

  • @yatin1370
    @yatin1370 Год назад

    Wonderfully compiled and delivered. Thanks for giving such crystal clarity in these fundamentals..

  • @StellaOloo
    @StellaOloo 2 года назад

    This is so detailed and easy to understand.Thank you

  • @mohammadahmedragab837
    @mohammadahmedragab837 Год назад

    thank you so much, your clear explanation made me understand the difference between var , let and cons. :)

  • @RahulSharma-oe6fy
    @RahulSharma-oe6fy 2 года назад

    Thank you for explaining the concept of variable leaking ! Never knew this happens with var

  • @jawidforotan3260
    @jawidforotan3260 3 года назад +1

    Your videos are amazing !!!

  • @Grihlo
    @Grihlo 2 года назад

    It might be considered as not the easiest topic but with your explanation it's clear! Thank you!

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

    Thanks, Dave!

  • @tymo3391
    @tymo3391 3 года назад +1

    Thank you, Dave! At 10:45 you marked three words "global" which are on seperate lines, and changed them simultaneously. How did you do that?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  3 года назад +2

      Highlight one of them and press Ctrl+D to select another. This is with VS Code on Windows.

  • @Monika-tx1ge
    @Monika-tx1ge 3 года назад

    Great explanation!

  • @Chlorine-DB
    @Chlorine-DB Год назад

    This guy is the god of JS

  • @NeoTheChoosenOne
    @NeoTheChoosenOne 4 года назад

    Great explanation, thank you!!!

  • @khairulislam-lp1iw
    @khairulislam-lp1iw 11 месяцев назад

    wow, loved it

  • @kevinjohnson1769
    @kevinjohnson1769 Год назад

    Great explaination

  • @taetaebeatz5578
    @taetaebeatz5578 3 года назад

    Dang...I thought I knew this stuff...lol...good content...I learned a lot

  • @ezozaezoza3472
    @ezozaezoza3472 2 года назад

    Мне очень жаль, что мало понимаю английский язык. Но я все равно понимаю эти уроки потому что вы объясняете очень хорошо и детально огромная вам благодарность

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

    Comment made after watching a useful video so I don't forget what it was about #2.
    Global scope -> Variable accesible through all the code and they are outside any function
    Block scope -> Variable inside curly braces (as things in for)
    Function Scope -> Variable inside a function
    The last two cannot be accessed outside the declared place, for function, it'll return undefined, for block scope, it'll have an error

  • @chanalan5846
    @chanalan5846 2 года назад

    Hi Dave, thanks for the teaching.
    I've got a question, when I enter ${x}; in the console it shows ${x} instead of the value.
    May I know if there is anyway to solve this? Thanks

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад

      ${x} will cause an error if that's all you type in the console. Unexpected token. Not sure why you would do that? If you have defined x as a variable, just type x.

    • @Grihlo
      @Grihlo 2 года назад

      Hi! I've had a similar issue recently and it was caused by using quotes (no matter singular or double '/") instead of backticks ``.

  • @tauhidhasan5527
    @tauhidhasan5527 2 года назад

    Thanks I am now clear

  • @ukaszpospiech3817
    @ukaszpospiech3817 3 года назад +1

    Var doesn't respect { } scope indeed! Thanks for pointing this out. And thanks for explaining that the notorious "block scope" simply means things like: if { } or for { } etc.

  • @damo190
    @damo190 2 года назад

    Sir, there is also a module scope. I saw in dmitripavlutin article that module scope can also be nested. How can I able to nest a module scope?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад +1

      You import modules. They do have their own scope. This should be covered in a future lesson. 💯

    • @damo190
      @damo190 2 года назад

      @@DaveGrayTeachesCode so, importing a module is called module scope nesting?

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад

      @@damo190 no, modules have scope. Functions can be within a module, too. Their scope would be inside (aka nested) the module. If you understand the scope discussion of this tutorial, it is all you need as a beginner 💯

  • @jamshidtashkent1976
    @jamshidtashkent1976 2 года назад

    Perfect

  • @damo190
    @damo190 2 года назад

    let a = {f(){console.log(this);}};
    Here, the value of 'this' depends from where the function f is called, not from where f is defined. So, I doubt 'this' is in dynamic scope. But I have already learned, JavaScript only supports lexical(static) scoping. That's why I am confused. Please help me.

    • @DaveGrayTeachesCode
      @DaveGrayTeachesCode  2 года назад +1

      In your example, "this" refers to the object you are creating. You will see this more clearly if you add a 2nd property like num: 10 or similar and then call the f method on the object a like: a.f() ..it will log the full object to the console. The "this" keyword can make things confusing in JS until you work with it for awhile.

    • @damo190
      @damo190 2 года назад

      @@DaveGrayTeachesCode so, this keyword is in which scope, lexical or dynamic?

  • @yigita3190
    @yigita3190 4 года назад +1

    Holy shit a youtube tutorial with a good microphone

  • @taetaebeatz5578
    @taetaebeatz5578 3 года назад

    Never underestimate the basics...

  • @anaswaras6305
    @anaswaras6305 2 года назад

    Awesome tutorial..Thanks a bunch!