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.
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 "{}".
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
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!
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
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
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?
@@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
@@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.
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.
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"❤️ 😀
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.🙏
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
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
@@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,
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!
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 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
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 ❤️
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!! 😊😍💖💖
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....
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
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😊😊🌟🌟
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.
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 !!
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.
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.
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
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
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. 👍
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!
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.
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
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. ❤️
#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.
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....
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.
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.
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?
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.
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.
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
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. ❤️
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?
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
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 .
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.
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.
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.
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;
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. 😌✌️
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.
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!!!
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
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 :)
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 🙏🙏
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. 🙏❤
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.
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
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❤❤") }
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.
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.
Even the creator of javascript couldn't have made me understand this concept like the way you did brother... Just amazing!
Couldn't agree more💯
You are absolutely correct.
Absolutely Right
Totally agreed!!
ok this is too much
Indian people always sharing much knowledge!
I'm grateful to Akshay and all of my Indian brothers 🙏
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.
Great dude you gave me new idea
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 "{}".
Code inside curly brackets is stored in separate memory space called block for let and const hence they are called block s
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
Beautifully summarized.
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!
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
@@bhavanachowdary3158 he link the js file with html page using script tag
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
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?
thanks brother
@@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
@@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.
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.
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"❤️ 😀
Haha, no man. I don't waste time while taking interviews talking all these informal things, every second is precious at that moment. 😇
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.🙏
I should take a snapshot of this comment and post it for people to save it for revision. Thank you for this Manisha ✌️
@@akshaymarch7 Sure , It's all your teaching 🙏.
Thanks broo
@momentswithmanisha.115 ismai aap lexical scope , lexical enviroment, scope-chain ,globel scope , function scope, clousers add kerdeytey too majaa ajaata
@@momentswithmanisha why block scope follows lexical scope chain pattern .
Does new execution contaxt created in case of block like functions
im normally not the one who comments, but because of you my java script foundations are stronger than ever.
so thank you so much.
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
Thank you, Vincent. Love from India ♥️
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
Me too, Me too...
Haha 😅
@@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,
@@farazk9729 watch this same video after a month. you will understand what he is saying.
@@akshaymarch7 plz upload more videos
Usually, no one tells you "Illegal shadowing". But you are revealing things so easily, thank you! 😇
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!
True dude
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👏😎👏
4 days into this playlist , I can proudly say that it's more addictive then a tv series . Next level stuff brother
Sometimes I feel that I should forget all those js concepts which I learn till now before watching Namaste Javascript...Thanks !!
No words can even describe you as a teacher, you're explanation is beyond compare.
This series in giving content like no other on RUclips. I request you to keep doing the same. We will be grateful to you.
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
But let is not supposed to be in global scope?
@@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
I have seen many js videos all over youtube but the way you describe, the deep dive into the concept you go is outstanding.
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 ❤️
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!! 😊😍💖💖
This is what I call Vidyadaan. Thank you Guru :)
Please do keep making videos. I always do keep checking your channel for new videos.
Thank you so much for your beautiful comment brother. ❤️
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....
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
Aapke ke jaisa js ka tutorial aur kahi nahi mila mujhe, dil jeet liya brother
Best JS tutorial watched ever. Completed the series at a go. Really excited for upcoming videos !!!
U give me confidence for attending interviews in big companies.Thank you Akshay , you are a life saver.
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😊😊🌟🌟
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.
No one has ever explained so neat and clean. Thanks Akshay, you are doing a fabulous job for making it free for us. ❤️
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 !!
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.
thank you 👍
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.
The way you are explaining( with excitement) awesome bro.. its makes me more interest.
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
Watching it again to refresh all the topics. please make a series on Nodejs toooo.🤩
learning javascript in 2024, this series is awesome
Believe me this series is the best javascript tutorial I have ever seen. Hats off to you👏🏻
This man's smile gives a lot of positivity❤
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
I binged this series and it's the best ❤️
block - group of statements enclosed within curly braces { } . It allows us to group multiple statement in single unit
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. 👍
I'm fall in love❤️ with javascript...so I want to marry javascript
@@Pavankumarsinglavqrdoor1242 bhai control
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!
You really made me fall in love with JS.
If possible please upload react Js and Angular Js videos also.🥺
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.
Hey Akshay, i love your enthusiast explaining things sometimes also not easy at all, keep it up bro
I've never seen any series related to programming with this much of interest and enthusiasm. ❤
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
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. ❤️
Very easily understandable video. Thank you so much.
#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.
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....
your content and the way you explain is amazing :)
Been three years since this video came out. This man is still the goat
Thanks a lot for this invaluable thing..
This is the best JS series to understand the core concepts deeply
Hugh Respect for your dedication Sir.
itna deep na koi smjha paya tha na smjha payega.... Bs aap ho sir
This video will be awesome I already know...
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 🙏🙏🙏
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.
So nice of you Adeete, thank you for your lovely comment. Feels like the effort is worth it. ❤️
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.
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?
hey i have same doubt ... did you get answer
@@rhythm1723 not yet
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.
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.
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
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. ❤️
Shadowing is the new concept I came to know today. very excited about the upcoming video :)
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?
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
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 .
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.
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.
Sir I never comment on any RUclips videos but after seeing your videos I will highly recommend others to watch your javascript playlist
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.
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;
I never seen any trainer to cover such a essential topic. I have no words to thank you. Great job! clap clap clap!!!
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.
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. 😌✌️
Perfect explanation ever on internet. Saying Genius would be just a work for your apprication, Salute you bro
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.
Every concept explanated very deep level no one explanation that much detail on RUclips thanks so much ❤️ ❤️👍
Eyes glued to your course. This concept was a bit tricky but finally got it. Thank you
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!!!
One of the best js series, I ever watched. 👍
You are explaining everything as it was simplest concept in the universe. Thank you!
If only we had teachers like him in our schools and colleges. We would have our own Google and Microsoft kind of software products.
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
Best JavaScript Tutor 🙌
Respect 🙏
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 :)
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 🙏🙏
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.
This is the best video on scoping! Period!
This is the best explanation of the block scope of JavaScript. Thank you very much
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. 🙏❤
akshay bhaiya is like a js hacker
beacuse bhaiya clear every deep concept of js amazing playlist 😍😍😍😍
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.
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
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.
Thank you so much for your beautiful comment brother, it means a lot! ❤️
Such A wonderful way to explain all basic but important topic!!
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❤❤")
}
Your teaching skills is absolutely amazing brother thank you.
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.
Thank you so much, it means a lot. ❤️
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'.
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.