Var and let keyword - Scope in Javascript

Поделиться
HTML-код
  • Опубликовано: 11 сен 2024
  • Welcome to a youtube channel dedicated to programming and coding related tutorials. We talk about tech, write code, discuss about cloud and devops. That’s what we do all day, all year. We roll out a lot of series and videos on our channel.
    All the learning resources such as code files, documentations, articles and community discussions are available on our website:
    chaicode.com/
    You can find our discord link, github link etc on the above website.
    Twitter/X link: x.com/hiteshdo...
    Discord link: hitesh.ai/discord
    Learn React with 10 projects: • Let's learn react from...
    Learn Docker: • A practical guide on D...
    Learn Kubernetes: • Complete Kubernetes Co...
    How does a browser works: • How does a browser wor...
    How nodejs works: • How node JS works | En...
    Learn Redux-toolkit: • Learn Redux Toolkit in...
    Learn NextJS: • Nextjs Full stack course
    Learn Typescript: • Why to learn Typescript
    Learn Javascript: • Welcome to new JavaScr...
    Learn React Native: • React Native Mastery: ...
    Learn Zustand: • React state management...
    Learn Golang: • How to get started wit...

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

  • @amans6504
    @amans6504 3 года назад +3

    if you're reading this, i got this after reading a ton of blogs
    It's very easy,
    1. var is functionally scoped ONLY
    2. let is block scoped
    3. a block is a code kept inside curly braces"{}". so basically a function, if statement or even random global curly braces are all blocks
    so basically, when u declare a function and declare a variable with var inside that function, the var is FUNCTIONALLY scoped and cannot be acessed by its parent(or in global scope) WHEREAS if you declare the same var inside an if statement, IT WILL easily be accessed in the parent scope because, var is functionally scoped ONLY
    whereas in the case of let, doesn't matter if you declare it inside a function or inside an if statement, in both the case it is not accessible in the parent scope, because function and if statement both are blocks afterall, and let is block scoped!
    basically just dont use var,use let and you'll be fine.

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

      Thanks for more clarification.

  • @pile333
    @pile333 6 лет назад +2

    A Nobel prize for teaching should be instituted and it should go to Hitesh Choudhary. ^_^
    Thx.

  • @prabhatjena5833
    @prabhatjena5833 6 лет назад +13

    very nice series..at rapid pace...if at the end of series one video comes chrome dev. tools for debugging Javascript..this will make a great js series...thnx..for tutorials..

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

    Ur explanation is good and clear. I was having a hell time with this subject during my course, until I found ur channel. Good job guys👍

  • @SP-ty5zw
    @SP-ty5zw 5 лет назад

    this is really like bahubali series for our code world.. amazing amazing , n+1 amazing, tq hitesh for this, hats off to u

  • @yashrajanshukla7790
    @yashrajanshukla7790 6 лет назад

    Eagerly waited for your rain of Javascript.. And then you posted this video in morning ... Amazing. Supee amazing video

  • @AtoZDominations
    @AtoZDominations 5 лет назад +2

    I don't understand, if we change iamGlobal inside the if block and call it outside the if block it should print 'somevalue', instead of superman. Why is it affecting the global variable outside the if block?

  • @shubhamsharma-pu2sp
    @shubhamsharma-pu2sp 6 лет назад +5

    Now I understand why you use LET

  • @sivathejeswarareddyk3149
    @sivathejeswarareddyk3149 6 лет назад +2

    Love the series

  • @kushaldhakal3009
    @kushaldhakal3009 6 лет назад +9

    By scope, I first thought of job opportunity, salary and something like that. Lol

  • @codingwithsam9194
    @codingwithsam9194 6 лет назад +2

    if the if() is false the code block doesn't runs right then why am I facing a problem with this code???
    let jj = 'code'
    if (false) {
    var jj = 'code1'
    }
    console.log(jj);
    nd the error is:
    /Users/samcomputer/node js/practice.js:3
    var jj = 'code1'
    ^
    SyntaxError: Identifier 'jj' has already been declared
    at createScript (vm.js:80:10)
    at Object.runInThisContext (vm.js:139:10)
    at Module._compile (module.js:607:28)
    at Object.Module._extensions..js (module.js:654:10)
    at Module.load (module.js:556:32)
    at tryModuleLoad (module.js:499:12)
    at Function.Module._load (module.js:491:3)
    at Function.Module.runMain (module.js:684:10)
    at startup (bootstrap_node.js:187:16)
    at bootstrap_node.js:608:3
    let me know why?

    • @danishnazirpeer3422
      @danishnazirpeer3422 6 лет назад

      Coding with sam you can't declare a variable twice...... In this case, u declared variable jj using let and then var

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

    Thanks sirji, most askable question in interview, now I am clear about lat and var declaration

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

    Huge respect for the content you are providing here..
    Been blessed after subscribing here😉😉

  • @Souravbaranwal
    @Souravbaranwal 5 лет назад

    Hey Hitesh, I've seen some of your videos and it really helped. Thanks a lot !!

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

    Nice explanation with example sir.

  • @SahilKumar-rw3sh
    @SahilKumar-rw3sh 2 года назад

    nicely taught , sir

  • @msdhaliwal
    @msdhaliwal 6 лет назад

    very helpful for both beginners and experts

  • @Bajrang.707
    @Bajrang.707 5 лет назад +2

    Thanks for this :)

  • @rajanchoudhary7432
    @rajanchoudhary7432 6 лет назад

    very nicely explained. Keep Uploading

  • @vinitsharma7735
    @vinitsharma7735 5 лет назад

    Hey Hitesh,
    Please let us know what are the changes done by you to save time and all.

  • @ashishpanjwani457
    @ashishpanjwani457 6 лет назад

    one of my fav playlist

  • @viralpatva7093
    @viralpatva7093 6 лет назад

    Very helpful tutorial.

  • @alid2756
    @alid2756 6 лет назад +3

    Hi Hatish, thank you for these amazing videos, how can I configure my integrated terminal in VScode to run my JS instead of windows cmd? thank you

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

      For windows: just change file association of .js file to node.exe
      1) Take VSCode
      2) Right click on the file in left pane
      3) Click "Reveal in explorer" from context menu
      4) Right click on the file -> Select "Open with" -> Select "Choose another program"
      5) Check box "Always use this app to open .js file"
      6) Click "More apps" -> "Look for another app in PC"
      7) Navigate to node.js installation directory.(Default C:\Program Files
      odejs
      ode.exe"
      8) Click "Open" and you can just see cmd flashing
      9) Restart vscode and open the file -> Terminal Menu -> "Run active file".

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

      @@vishaldivekar09 Thank you

  • @gauravk4050
    @gauravk4050 6 лет назад

    #unstoppable
    love this playlist..😻

  • @koustubhmuktibodh4901
    @koustubhmuktibodh4901 5 лет назад

    Sir great explanation !

  • @rajeshkumarsahoo
    @rajeshkumarsahoo 6 лет назад

    Awesome clarification

  • @sachintiwari5871
    @sachintiwari5871 6 лет назад

    Great sir.....
    #Unstoppable....

  • @thedeepeffect_
    @thedeepeffect_ 5 лет назад

    if we look at the bright side of this var problem is that....if we want some variable to be defined in some conditions only and if that condition is true.......we will use that variable in our program for further use.....else we won't use that variable.........
    PS:Correct me if i'm wrong :)

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

    Thanks

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

    yo, so with the value part. i dont know if im doing something wrong but this is the code
    let iAmGlobal = "someValue"
    if (true){
    let iamLocal = "someMoreValue";
    iAmGlobal = "superman";
    console.log(iAmGlobal);
    console.log(iamLocal);
    }
    console.log(iamLocal);
    console.log(iAmGlobal);
    Output:node scope.js
    someValue
    someMoreValue
    each time please answer me.

  • @niharikakuravii7420
    @niharikakuravii7420 6 лет назад

    great series sir

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

    if 'iAmGlobal' was reassigned a value inside if block, shouldnt its scope be inside block only. Why does its value changes outside the block later on? Do kindly reply!

  • @harshitawasthi2420
    @harshitawasthi2420 5 лет назад

    Sir If i have same name variable in global as well as local scope and if i access that variable inside local scope it will give preference to local variable . So how could i use that global variable inside local scope ?

  • @imaginarytechinhindi5507
    @imaginarytechinhindi5507 6 лет назад +2

    'let' keyword is used to declare constants in Swift...

    • @RockDavid
      @RockDavid 5 лет назад +1

      Well good thing this isn't Swift, nor your comment has anything to do with Javascript..
      Good times, ohh and the world is flat

  • @deepak_dalvi
    @deepak_dalvi 6 лет назад

    Hiee..Thank you making this kind quility videos for JavaScript.
    I want to know there is any way to pass variable from javascript to PHP

  • @nayandas-ld4zp
    @nayandas-ld4zp 5 лет назад

    Great ...!

  • @jincypaul05
    @jincypaul05 5 лет назад

    Sir, How did you access the terminal inside VSCode. Can you please answer?
    Thank you very much for the amazing JavaScript series!!!!!!

    • @neelakshsharma4936
      @neelakshsharma4936 5 лет назад

      Just go to the terminal option displayed in the top and select New Terminal. Or simply press ctrl + shift + '

  • @amishaa9555
    @amishaa9555 6 лет назад

    i am so enthusiastic that i will definitely try to work harder and smarter and master the course

  • @codingwithsam9194
    @codingwithsam9194 6 лет назад

    Ok sir nice but please upload your live stream today. I have plenty of questions to ask you...

  • @bhanurulz
    @bhanurulz 6 лет назад

    lot of respect :)

  • @Devank12
    @Devank12 6 лет назад

    thank you sir,how to add terminal in the VS please make a video

  • @amitojsinghahuja4330
    @amitojsinghahuja4330 6 лет назад

    thankyou!!!

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

    IF I OPEN THE TERMINAL IT SAYS 101 error crash and whole thing closes andthe folder also got closed
    pls help me how to fix it

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

    But this concept does not working in function why this so
    Can you explain.

  • @AreAreTv
    @AreAreTv 5 лет назад

    Hi, how can email you because i have a project and need to create a special calculator, i will pay. Please contact me privately. Thank you.

  • @petrospetrosyan1414
    @petrospetrosyan1414 4 года назад +2

    What's the difference between using “let” and “var”?

  • @AbhishekGupta-xh5si
    @AbhishekGupta-xh5si 6 лет назад

    how to do tab on typing 'log' so it becomes the whole thing?

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

    when I am writing if statements in vscode and I fill in the condition, it doesn't autocomplete variable names. Anyone know how I can fix this?

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

    hitesh how can i take input from user

  • @sushilknm06
    @sushilknm06 5 лет назад

    your every series in mac os ,is there something for windows?

    • @HiteshCodeLab
      @HiteshCodeLab  5 лет назад

      Written in VSCode, executed in browser. All tools used are cross platform.

  • @sriharshajaddu3426
    @sriharshajaddu3426 6 лет назад

    Phases of web development for learning 1st html or css or js please reply would be helpful??!

    • @HiteshCodeLab
      @HiteshCodeLab  6 лет назад

      Already did an extensive series on front end at my website, learncodeonline.in

  • @papachoudhary5482
    @papachoudhary5482 6 лет назад

    Nice

  • @bikkyjbn4065
    @bikkyjbn4065 6 лет назад

    Bro need your help in my affiliated flipkart dashboard shoing migrate to new api version .so how to solve this .hope u will solve my problem .please reply me bro... i m waiting ..

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

    for(var i=1;i

  • @yashshende2786
    @yashshende2786 6 лет назад +2

    first

  • @debasishdutta9073
    @debasishdutta9073 5 лет назад

    Amazing..
    But i have a question for you.......
    ..1)Who r you?
    2)What is your main job?
    3)How many programming language do you know very well?

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

    let iAmGlobal = "someValue";
    if (true) {
    var iAmLocal = "someMoreValue";
    //let iAmLocal = "someMoreValue";
    iAmGlobal = "superman";
    console.log(iAmGlobal);
    console.log(iAmLocal);
    }
    //console.log(iAmLocal);
    console.log(iAmGlobal);

  • @vimalsingh3544
    @vimalsingh3544 6 лет назад

    sir pls tell how we can give user input in javascript

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

    It would have been much good if "const" is also there.

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

    Nice try. :)

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

    Confusing

  • @kylenakamura4353
    @kylenakamura4353 5 лет назад

    This "wideo" should have only been 2 minutes long. Way too in depth.