BLOCK SCOPE & Shadowing in JS 🔥| Namaste JavaScript 🙏 Ep. 9

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

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

  • @programmed509
    @programmed509 3 года назад +707

    Even the creator of javascript couldn't have made me understand this concept like the way you did brother... Just amazing!

  • @drapala97
    @drapala97 3 года назад +420

    Indian people always sharing much knowledge!
    I'm grateful to Akshay and all of my Indian brothers 🙏

  • @jagrutsharma9150
    @jagrutsharma9150 2 года назад +288

    Things learned:
    1. Code inside curly bracket is called block.
    2. Multiple statements are grouped inside a block so it can be written where JS expects single statements like in if, else, loop, function etc.
    3. Block values are stored inside separate memory than global. They are stored in block. (the reason let and const are called block scope)
    4. Shadowing of variables using var, let and const.
    5. The shadow should not cross the scope of original otherwise it will give error.
    6. shadowing let with var is illegal shadowing and gives error.
    7. var value is stored in nearest outer function or global scope and hence can be accessed outside block as well whereas same is not the case with let and const.

    • @laxmanshrivas1500
      @laxmanshrivas1500 Год назад +4

      Great dude you gave me new idea

    • @abdullahsoomro6238
      @abdullahsoomro6238 Год назад +11

      In point number 2 I want to add something. If function is defined using the "function" keyword, then "{}" are a part of its syntax. If we miss that we will get error. But in case of arrow functions, it is fine when we have just one statement in it, we can opt out "{}".

    • @koreanrhythm8248
      @koreanrhythm8248 Год назад +3

      Code inside curly brackets is stored in separate memory space called block for let and const hence they are called block s

    • @swastiksharma2738
      @swastiksharma2738 Год назад +6

      we can shadow a let variable with var only if we are declaring it in a function as explained by ​ @abdullahsoomro6238 { } is part of function's syntax.
      for ex: let a = 10;
      function func(){
      var a = 20;
      }
      this wouldn't give any error

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

      Beautifully summarized.

  • @sakshirathi3077
    @sakshirathi3077 8 месяцев назад +16

    Key Learnings
    Block is also known as Compound statements. It is used to combine the multiple statements together
    let & const are hoisted in a block scope. var is in global scope
    let and const variables are stored in block space, so it is called block-scoped but var variables can be accessed outside the block as it is stored in the Global object memory space, hence it is called Global scoped.
    Variable shadowing occurs when a variable declared in an inner scope has the same name as a variable in an outer scope, effectively hiding the outer variable within that scope.
    Example 1:
    let x = 10; // Outer scope variable
    function example() {
    let x = 20; // Inner scope variable, shadows outer 'x'
    console.log(x); // Prints 20
    }
    example(); //function call
    console.log(x); // Prints 10
    Example 2:
    var a = 199;
    {
    var a = 10;
    }
    console log(a);
    variables declared with var are function-scoped or globally scoped, but they are not block-scoped like variables declared with let or const. So, the var a declared inside the block {} will override the outer var a declaration, and the value of a will be 10 when logged outside the block.
    var variable of function scoped overwrites the value of Global Scoped variable.
    Scope for arrow function is also same!

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

      can you explain how he has excuted they .js file with the help of livesever or some other way because while implementing practically I can't able to debug like him in chrome

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

      @@bhavanachowdary3158 he link the js file with html page using script tag

  • @0xFOXHOUND
    @0xFOXHOUND 4 года назад +177

    First Love your explanation with examples Akshay sir, videos are exact on point!!!
    For Revision:
    Q) What is block in JavaScript?
    > multiple js statements formed in a group enclosed in brackets and it forms a block
    Q) What is need of a block/Grouping?
    > JavaScript sometimes expect to run a single statement to run, but we need to run commands with multiple statements which is only possible by block
    eg. on 4:14
    write a simple function:
    // even empty script is perfectly valid js script, what about empty brackets!!
    {
    var a = 10;
    let b = 20;
    const c =30;
    }
    When a js script get hoisted (a Global Execution Context) gets created 'var' listed towards 'Global environment' and other variables 'let' and 'const' declarations go to the 'Block environment'
    This become especially important when deciding the scope of a particular variable, since b and c are located in 'Block environment' and for a as we know exists in 'Global environment' any statement out of the "Block" can access 'a' ie. ' Variable in Global environment' and other are not!
    so when we understand the extent of Global and local environment variables and their 'Scopes' == Environment that forms the lexical hierarchy of 'Scopes' and 'Scopes' have Levels like 'Scope inside scope'
    see script in 7:03
    var a = 100;
    {
    var a = 10;
    let b = 20;
    const c =30;
    console.log(a);
    console.log(b);
    console.log(c);
    }
    console.log(a);
    console.log(b);
    console.log(c);
    So in block " var a = 10;" influences the value within the block hence console.log(a); >> 10 and outside of the block 'Variable in Global environment' influences value of a hence console.log(a); >> 100
    Illegal shadowing:
    let a = 200;
    {
    var a =20;
    }
    as 'var' declaration goes to 'Global environment' and sets in Memory context, it cannot be set using 'Block environment' value Hence: Uncaught SyntaxError: Identifier 'a' has already been declared

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

      Here a question then :
      var a=100;
      {
      console.log(a)
      var a=10
      }
      What would be the expected value of this program according to the concepts explained?
      Since we say the block influences the variable, then will we get undefined(due to variable being referred before it was declared in the lexical scope) or will we get 100?

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

      thanks brother

    • @0xFOXHOUND
      @0xFOXHOUND 3 года назад +1

      ​@@dgdivyanshugupta first var a=100 affect the inner scope value (consider it as a onion) as outer exec context is covering inner exec. context
      so sorry for super late reply

    • @RM-lb7xw
      @RM-lb7xw 3 года назад +18

      @@dgdivyanshugupta var doesn't follow block scope so your code is basically the same as
      var a = 100;
      console.log(a);
      var a = 10;
      So the code will log the value 100. Now lets say we had let or const instead of var in your code. So the code becomes:
      let a = 100;
      {
      console.log(a);
      let a = 10;
      }
      Since let and const follow block scope, the above code will throw a ReferenceError saying it cannot access 'a' before its initialized. The best way to understand this is by looking at those brackets {}. SInce a is being logged on to the console before its initialized in the {}, it throws an error. Thats what block scope's all about.

    • @mahabaskaran6359
      @mahabaskaran6359 3 года назад +4

      I have a question on illegal shadowing.
      let a = 200;
      {
      var a =20;
      }
      `let` goes to different memory called "script" and var goes to "Global". Why is it mentioned as crossing boundaries in the video. Can someone please explain me this.

  • @prafulsinghvit
    @prafulsinghvit 4 года назад +95

    Now, I am just imagining how much fun it might be for you, when you interview candidates and they give absurd answers to the very core questions like this , and you asking them to go refer "Namaste JavaScript"❤️ 😀

    • @akshaymarch7
      @akshaymarch7  4 года назад +59

      Haha, no man. I don't waste time while taking interviews talking all these informal things, every second is precious at that moment. 😇

  • @momentswithmanisha
    @momentswithmanisha 3 года назад +81

    Block :- It is used to combine multiple statement into one statement so that we can use it at those places where javascript expects to have single statement.
    Scope :- scope of a variable or a function is the place where these are accessible.
    Block scope :- The variables and function present within the scope of a block section. And block follows the lexical scope chain pattern while accessing the variable.
    Shadowing :- Providing same name to the variable as of those variable which are present in outer scope.
    Thanks Akshay for clearing the concept so nicely.🙏

    • @akshaymarch7
      @akshaymarch7  3 года назад +27

      I should take a snapshot of this comment and post it for people to save it for revision. Thank you for this Manisha ✌️

    • @momentswithmanisha
      @momentswithmanisha 3 года назад +6

      @@akshaymarch7 Sure , It's all your teaching 🙏.

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

      Thanks broo

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

      @momentswithmanisha.115 ismai aap lexical scope , lexical enviroment, scope-chain ,globel scope , function scope, clousers add kerdeytey too majaa ajaata

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

      @@momentswithmanisha why block scope follows lexical scope chain pattern .
      Does new execution contaxt created in case of block like functions

  • @iStrikeFirst
    @iStrikeFirst 4 года назад +28

    im normally not the one who comments, but because of you my java script foundations are stronger than ever.
    so thank you so much.

  • @vincent3542
    @vincent3542 2 года назад +48

    Akshay is the best Guru ever, why? because it not only teaches basic concepts systematically, but teaches with passion, this can be the initial trigger where students start to be interested in diving further.
    Best regards from Indonesia

    • @akshaymarch7
      @akshaymarch7  2 года назад +10

      Thank you, Vincent. Love from India ♥️

  • @tatatabletennis
    @tatatabletennis 4 года назад +203

    We have seen people waiting for Money heist or GOT season release
    I am waiting in a similar way for Akshay Saini videos
    Namaste JavaScript is a super cool series..
    Highly useful for JavaScript lovers
    Foundations are getting stronger and stronger

    • @SABBIRAHMED-ml4dy
      @SABBIRAHMED-ml4dy 4 года назад +5

      Me too, Me too...

    • @akshaymarch7
      @akshaymarch7  4 года назад +12

      Haha 😅

    • @farazk9729
      @farazk9729 3 года назад +9

      @@akshaymarch7 Akshay, for the first time, I found your teaching a bit confusing and unclear.
      I just wish you had included the visual representation of everything in this lesson. (Remember how you drew the execution context, the memory phase, the code phase? It was perfect! I wish you had visually INCORPORATED the scope concept into your drawing. The visual representation was great, but when you teach new things, it will raise questions; how should I draw the script, the global scope, etc etc in my visual drawing?)
      Thanks,

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

      @@farazk9729 watch this same video after a month. you will understand what he is saying.

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

      @@akshaymarch7 plz upload more videos

  • @amitjoshi956
    @amitjoshi956 3 года назад +14

    Usually, no one tells you "Illegal shadowing". But you are revealing things so easily, thank you! 😇

  • @robertobenedit
    @robertobenedit 2 года назад +12

    I have had hundreds of tutorials along these years, this "Namaste" series is the best of the best. The junction of simplicity, deep knowing, and pasion is a bullet into the brain, just amazing!

  • @parmarhitendrasinh4504
    @parmarhitendrasinh4504 4 года назад +28

    This series deserves more views and liked it should be on facebook and youtube adds. Its getting more and more amazing.Big Shout out to AKSHAY👏😎👏

  • @shubhampanwar3906
    @shubhampanwar3906 2 года назад +9

    4 days into this playlist , I can proudly say that it's more addictive then a tv series . Next level stuff brother

  • @harshilparmar9076
    @harshilparmar9076 4 года назад +15

    Sometimes I feel that I should forget all those js concepts which I learn till now before watching Namaste Javascript...Thanks !!

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

    No words can even describe you as a teacher, you're explanation is beyond compare.

  • @JS-zm5se
    @JS-zm5se 4 года назад +10

    This series in giving content like no other on RUclips. I request you to keep doing the same. We will be grateful to you.

  • @Anoyashu
    @Anoyashu 3 года назад +6

    If you didn'nt understood illegal shadowing read this.......
    illegal Shadowing : var is not scoped to the block it's in, it's scoped to the containing function. If there is no containing function, it ends up in the global scope. Hence it conflicts with the let a declaration which is conflicting during code component phase

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

      But let is not supposed to be in global scope?

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

      @@jamalbutt7864 lexical scoping comes here( when in block let a is checked the block also have access to global) which create a conflict during run time

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

    I have seen many js videos all over youtube but the way you describe, the deep dive into the concept you go is outstanding.

  • @NiyatiShah24
    @NiyatiShah24 3 года назад +11

    Cannot even imagine how much research and work must've gone into this. Also dissecting it into simple understandable bits. You are the best teacher ever ❤️

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

    Even on my last interview which I have appeared a few weeks ago, I told the same to the interviewer about "let and const" without knowing what is the in-depth mechanism behind it. These explanations were really in need, even for person who are experienced in JS. THANK YOU AKSHAY!! 😊😍💖💖

  • @sathishpai4868
    @sathishpai4868 4 года назад +12

    This is what I call Vidyadaan. Thank you Guru :)
    Please do keep making videos. I always do keep checking your channel for new videos.

    • @akshaymarch7
      @akshaymarch7  4 года назад +4

      Thank you so much for your beautiful comment brother. ❤️

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

    this is one of the most important concept and trust me in interviews i have seen like 100 of questions which directly and indirectly comes from this concept.... very well explained.... thanks a lot Akshay bhaiya....

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

    Never in my life i ve dived this deep in concepts of any language ALL Thanks To you Brother , you made all these interview topics so easy that one can easily understand and answer all the questions plus this mad javascript more fun to learn

  • @thetube-science8884
    @thetube-science8884 2 года назад

    Aapke ke jaisa js ka tutorial aur kahi nahi mila mujhe, dil jeet liya brother

  • @abhisekpradhan9353
    @abhisekpradhan9353 4 года назад +7

    Best JS tutorial watched ever. Completed the series at a go. Really excited for upcoming videos !!!

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

    U give me confidence for attending interviews in big companies.Thank you Akshay , you are a life saver.

  • @kasifmansuri7552
    @kasifmansuri7552 Год назад +3

    No Such Thing As Bad Student, Only Bad Teacher.....I don't know but this quote strikes in my mind after watching half series...Loved it Akshay bhai😊😊🌟🌟

  • @Student__.
    @Student__. 10 месяцев назад

    Honestly, i was just trying to memorize these concepts before, but I didn't know somebody could explain all this so easily. You have exceptional teaching skills. Thanks a lot for this series.

  • @debs1991
    @debs1991 4 года назад +3

    No one has ever explained so neat and clean. Thanks Akshay, you are doing a fabulous job for making it free for us. ❤️

  • @akshatadeshpande-tq7pu
    @akshatadeshpande-tq7pu 10 месяцев назад

    The way you are explaining JavaScript, i literally like how beautifully it is designed and thank you for realising a developer that Javascript is so beautifully designed 😃 your videos are awesome !!

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

    Here is the full notes of the video:
    1. Block : { }, this is a perfect example of a block. Block is also known as Compound Statement. Block is used to combine multiple JS statements into one group.
    2. Block scope means what all variables and functions we can access inside the block.
    3. Eg : {
    var a = 10;
    let b = 20;
    const c = 30;
    }
    'a' is hoisted in the global memory space, whereas let and const i.e., 'b' and 'c' are hoisted in some other memory space which is known as "Block". And that's why we say let and const are block scoped. When JS engine finishes executing this block, 'b' and 'c' will be no longer accessible outside this block. But you can access 'a' outside of this block, because 'a' is globally scoped.
    4. Eg :
    var a = 100;
    {
    var a = 10;
    console.log(a);
    }
    Output : 10
    Here, local variable 'a' shadows the global one in that block, that's why the value of 'a' in the block is 10 and not 100. Moreover, the value of 'a' is altogether changed to 10, and that's why if you'll try logging 'a' outside this block, you'll get its value as 10. This happened because both the 'a' are pointing towards the same memory location, which is there in the global scope.
    But, this is not in the case of let and const declarations, local let declaration cannot shadow the global let declaration, in a block.
    Eg : let a =1;
    {
    let a = 10;
    }
    The local 'a' here cannot shadow the global 'a' here, because the scopes in which these 'a' are falling are different, and hence the memory locations of both these variables will be different, local 'a' is stored in Block while global 'a' is stored in global memory space. Hence, the manipulation in one cannot affect the other. Similar type of behavior is also expected in case of const declarations. Shadowing works the same way in case of functions as well, since we can assume functions as a block only.
    5. Illegal Shadowing :
    Eg : - let a = 10;
    {
    var a = 20;
    }
    This is an example of illegal shadowing, you cannot shadow a let variable using a var declaration in a block. You can shadow a let declaration using a let, but not var. Because, in the same scope, let cannot be re-declared.
    But, we can shadow like this :
    let a = 10;
    {
    let a = 20;
    }
    Because, here 'a' has different scopes, one is block and one is global scope, so re-declaration can be done here.
    6. Lexical block scope with code example :
    Eg : - let a = 10;
    {
    {
    console.log(a);
    }
    }
    In the above example, the variable 'a' is declared in the global scope, but this 'a' can be accessed inside any block or any inner block. Firstly, the JS engine tries searching for 'a' in the current block it is executing, if it does not find there, it searches 'a' in the immediate ancestral lexical environment, and if still does not find there too, it expands it search to higher ancestral lexical scopes, it finds 'a' in the global scope, took its value, and printed on the console.

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

    After watching just 3 mins of this video, I can say that you are a scientist of javascript. You can easily crack Google interviews but you are here to help us. Every Indian should learn computer science from you.

  • @rajuch1999
    @rajuch1999 4 года назад +6

    The way you are explaining( with excitement) awesome bro.. its makes me more interest.

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

    For anyone who wants to lead there life working with javascript they should visit this channel first and after this course i am damm sure anyone can be enlightened to the core about javascript , Thanks a lot Akshay

  • @rushikanalamwar8320
    @rushikanalamwar8320 3 года назад +4

    Watching it again to refresh all the topics. please make a series on Nodejs toooo.🤩

  • @pradiptadagar9883
    @pradiptadagar9883 6 месяцев назад +3

    learning javascript in 2024, this series is awesome

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

    Believe me this series is the best javascript tutorial I have ever seen. Hats off to you👏🏻

  • @redonthebeatboi
    @redonthebeatboi 3 года назад +8

    This man's smile gives a lot of positivity❤

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

    After watching every video of the series i tried it in my browser and it work like magic. then i google about this concept and now i can understand each and every article about the JavaScript. Thanks to Akshay Saini Sir

  • @tarkeshkandregula6559
    @tarkeshkandregula6559 4 года назад +3

    I binged this series and it's the best ❤️

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

    block - group of statements enclosed within curly braces { } . It allows us to group multiple statement in single unit

  • @varnikaraghav3781
    @varnikaraghav3781 4 года назад +25

    Although I know this video gonna be another hit coz you explain everything so amazingly and in depth. Anybody watching these js videos will definitely fall in love with JavaScript. Please it’s a request make videos on more JavaScript concepts and also on Angular 6+ concepts. 👍

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

    I just logged into to leave a comment which I don't normally do. After watching a few other videos on topic with no answer - Your information just clicked and helped me with issue I was having in software Im developing. Thank-you!

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

    You really made me fall in love with JS.
    If possible please upload react Js and Angular Js videos also.🥺

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

    Your passion for teaching is contagious. Eager to learn more about the subjects you teach that they’re always coming to me with new discoveries. Thanks a lot.

  • @corsaronero5619
    @corsaronero5619 4 года назад +5

    Hey Akshay, i love your enthusiast explaining things sometimes also not easy at all, keep it up bro

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

    I've never seen any series related to programming with this much of interest and enthusiasm. ❤

  • @gautammalik6146
    @gautammalik6146 4 года назад +4

    This video is again one more gem from Akshay.... thanks for taking your time for the world.... in the end you have mentioned that normal function and arrow functions are same could you please also explain why then bind apply call not works with arrow functions....if you can make a video on this it would be very very helpful to clear the conflict between these two types of functions. Thanks again for this awesome work

    • @akshaymarch7
      @akshaymarch7  4 года назад +3

      Let me correct, I said `Scope behaves the same way in Arrow functions, just like Normal functions` 😇
      But arrow functions are NOT same as Normal functions.
      Actually, I've planned to make a separate video altogether for `Arrow Functions`, keep watching brother. Everything will be covered. ❤️

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

    Very easily understandable video. Thank you so much.

  • @dibyendubiswas1998
    @dibyendubiswas1998 4 года назад +6

    #LovingIt
    Please continue this series sir.
    If you continue then after 2 or 3 months I will become a decent JS developer.
    Lots of Love and Happy Dewali.

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

    awesome tutor till now in JS, today i learn proper global scope with 1 example.
    declare var a = 100; in one js file and place console.log('value from 1st file in another file', a); in another file and know what???? this actually prints value of a because of global memory allocation. its clear because of your memory allocation videos....

  • @shilpidhiman4941
    @shilpidhiman4941 4 года назад +3

    your content and the way you explain is amazing :)

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

    Been three years since this video came out. This man is still the goat

  • @naveenraj1161
    @naveenraj1161 4 года назад +3

    Thanks a lot for this invaluable thing..

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

    This is the best JS series to understand the core concepts deeply

  • @prakharkhandelwal7339
    @prakharkhandelwal7339 4 года назад +3

    Hugh Respect for your dedication Sir.

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

    itna deep na koi smjha paya tha na smjha payega.... Bs aap ho sir

  • @prosenjitghosh2218
    @prosenjitghosh2218 4 года назад +3

    This video will be awesome I already know...

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

    I have seen many js videos no one can explain like you, explain amazing way that can understand basic js i am salute to you sir 🙏🙏🙏

  • @adeete09
    @adeete09 4 года назад +7

    Great explanation akshay and it's really commendable that even after having a full time job you are taking out so much time to help everyone with such great content. Hats off to you.

    • @akshaymarch7
      @akshaymarch7  4 года назад +4

      So nice of you Adeete, thank you for your lovely comment. Feels like the effort is worth it. ❤️

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

    Block is set of statements in JS where Js expects a single statement.
    Lexical scope (Local memory + Reference to Lexical enviroment of its parent) works same inside the block also.
    let and const are block scoped and they would reside in a separate memory called block unlike var which has global scope.
    Shadowing is basically overriding of the variable.
    Illegal shadowing:- Shadowing of let to var and it will throw syntax error.

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

    Nice videos Akshay!
    I have one doubt,
    If let creates a different scope for 'a', then why can't we shadow it using var, it will be a different scope, right?

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

      hey i have same doubt ... did you get answer

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

      @@rhythm1723 not yet

    • @shubhamsingh-cd7iv
      @shubhamsingh-cd7iv 2 года назад +1

      I think because var has scope outside the block as well. So when control exits the block and comes into global scope, var a comes into direct conflict with let a. This is a case of redeclaration which let doesn't allow. That is why, we can shadow let a by function-scoping the var a.

    • @Divya-h5w
      @Divya-h5w 3 месяца назад

      Because var is not block scoped. It is global scoped and functional scoped where as let and const are block scoped and functional scoped. So var inside block scope is allocated in global memory and then we have let variable so we get error as it already exists.

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

    loved the video ... understood the difference between block and scope, block is used to write multiple statements where javascript would expect one statement; whereas scope defines the variables and functions that we can access from the part of code

  • @akshaymarch7
    @akshaymarch7  4 года назад +52

    Next Video: CLOSURES in JS 🔥 - ruclips.net/video/qikxEIxsXco/видео.html
    How was this video? Are you feeling excited? Let me know in the comments below. ❤️

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

      Shadowing is the new concept I came to know today. very excited about the upcoming video :)

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

      Are functions block scoped? When I declare a function inside a block, then I could see it in global scope as undefined hoisted. When execution enters inside the block, then the function is seen in the Block scope as well as global scope? Is this some other concept?

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

      Thank you sir for making these videos. After watching your video i played with my program to see
      How it handle everything behind the scene and after sometime i found some interesting things that when u use type="module" in your script tag the js engine will put all the variables and func. and class in module scope also when we put a function in block it behave differently . Sir can you make a video
      On this topic ?
      Thank you very much and stay healthy

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

    Your explaining skill is next level .
    Something we know that how to implement it but we dont know how does it exactly work ,you explain it in proper way .

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

    Watched it again and again, practices it, now finally i'm clear with block, block scope, shadowing, illegal shadowing,
    Thank you Akshay Saini it was helpful.

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

    Again an amazing video. And I request to everyone(inc. ME), to practice this shadowing concept right now to understand in-depth, otherwise, we may easily forget.

  • @MUSKANAHERWAR-u6g
    @MUSKANAHERWAR-u6g 2 месяца назад

    Sir I never comment on any RUclips videos but after seeing your videos I will highly recommend others to watch your javascript playlist

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

    For the first time, I have discovered the block scope in this video. many many thanks, just amazing explanation. even got the clear concept on Let and const, how they behaves and why.

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

    am amazed that some fundamentally important concepts are so nonchalantly glossed in so many "intro" texts/docs;
    Thank you sir, for explaining in such an accessible manner;

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

    I never seen any trainer to cover such a essential topic. I have no words to thank you. Great job! clap clap clap!!!

  • @Anjali-rc9mg
    @Anjali-rc9mg 6 месяцев назад

    the best course i have come across so far. i really appreciate the work done by akshay. a good mentor is really difficult to find.

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

    When you said the compound statement I remember the time when my teacher taught me this in 12th standard. Very important and basic concept which every logically thinking developer must know without just mugging up and giving answers like you have given examples in the beginning of the video. Great explanation and remarkable efforts. 😌✌️

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

    Perfect explanation ever on internet. Saying Genius would be just a work for your apprication, Salute you bro

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

    Summary:
    - Block or compound statement are code inside a curly brackets ({})
    - Block compains multiple statement into one group.
    - Block can use in where js expects single statement.
    - Block scope means that what all variables and functions that can access in block.
    - Block scope also follows lexical scope.
    - Let and const are block scope means, they are stored in separate memory space which is reserved for these block.
    - Shadowing in js, means use same variable name to shadow variables which is outside the scope.
    - In function scope it is also shadow similar way. Arrow function scope is same as funcition scope.
    - Illegal shadowing happens when a let or const is shadowed using var in block scope. But in function scope this is allowed.

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

    Every concept explanated very deep level no one explanation that much detail on RUclips thanks so much ❤️ ❤️👍

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

    Eyes glued to your course. This concept was a bit tricky but finally got it. Thank you

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

    I was learning all these concepts from last one month, but still I was asnwering wrong during some of basic quetions. Once I went though your videos on closure, prototype, JS engine and event loop, scope chain.... all concepts are clear... Thanks Akshay you are AWESOME!!!

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

    One of the best js series, I ever watched. 👍

  • @TenNiepokorny
    @TenNiepokorny 10 месяцев назад

    You are explaining everything as it was simplest concept in the universe. Thank you!

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

    If only we had teachers like him in our schools and colleges. We would have our own Google and Microsoft kind of software products.

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

    Earlier I tried so many times to understand all these concepts but got confused
    But your way of explaining things , it clear all your concepts
    Thanks a lot for the wonderful vedio series

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

    Best JavaScript Tutor 🙌
    Respect 🙏

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

    It's seems to be 1 on 1 teaching. The way you explain things and your gestures gives the experience of like i am sitting in front of you in class which builds up interest to learn more. Thanks a lot :)

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

    Watching the series in 1 go. Stopped here to just say - Thank you Bhaiya.❤ You are one of a kind Gem.
    I fell in love with JavaScript because of you.
    Plz make me fall in love with the cousins React js and Node js as well❤
    Ishwar tarrakki de aapko 🙏🙏

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

    a motivation u gave me to learn more about JS is speechless man, thanks for everything.
    a best video to learn everything about let, var & const.

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

    This is the best video on scoping! Period!

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

    This is the best explanation of the block scope of JavaScript. Thank you very much

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

    Vaiya, now I feel that I understand some Javascript only because of your Namaste Javascript Series. The way you dive deep into each concept and make every complex concept crystal clear, is amazing ! U have made my Javascript basics strong, Thank you Vaiya. Aise hi bhaut sare series laate rhna. 🙏❤

  • @mininikku-e8l
    @mininikku-e8l 3 месяца назад

    akshay bhaiya is like a js hacker
    beacuse bhaiya clear every deep concept of js amazing playlist 😍😍😍😍

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

    Uff !! what an amazing explanation. I am js developer for 3 yrs, I understand these concepts like never before. Amazing work Akshay, keep up the good work going. Great work.

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

    I have erased all my previous knowledge of JS and Learning JS from Namaste JS. Now I confidently say.. YES!! I know JS.. I am actually falling in love with this JS language with these videos

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

    this guy really deserves the credit for his efforts. No one will teach you javascript the way he teaches. This has to be paid content.

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

      Thank you so much for your beautiful comment brother, it means a lot! ❤️

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

    Such A wonderful way to explain all basic but important topic!!

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

    What is a block :
    A block is a space between two curly braces.
    Why do we use a block?
    A block can be used to combine multiple statements together , which can be used at places where JavaScript expects one single statement.
    eg
    if(true)console.log("hi")
    now if we use block
    if(5>4){
    console.log("eg of block")
    console.log("Hello")
    console.log("Thanks Akshay for such a content❤❤")
    }

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

    Your teaching skills is absolutely amazing brother thank you.

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

    Hi Akshay,
    I watched the complete playlist yesterday. Surely, came across some new things. Thank you.
    it's almost been 1 year, since i started coding in JS. Looking forward to more amazing content :)
    Btw my elder brother who's been doing the same for quite a while now, has huge respect for your content.

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

      Thank you so much, it means a lot. ❤️

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

    I'm new to coding but I think I'm getting it, slowly but surely. In my case it's about repeating the video over several times until it 'sticks'.

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

    Truly appreciating the effort that you're putting here on YT to explain intricacies of JS to us beginner . Please make a video on all the use cases of "THIS" Keyword in JavaScript.