Closure :Function bundled with its lexical environment is known as a closure. Whenever function is returned, even if its vanished in execution context but still it remembers the reference it was pointing to. Its not just that function alone it returns but the entire closure and that's where it becomes interesting !! Thank you so much, Akshay for this :) :)
Four things I like about Akshay. 1) Doesn't try and speak in an American accent, like most Indian TH-cam programmers. 2) Passionate 3) Someone with real knowledge. 4) A talented teacher.
Next Video: setTimeout + Closures Interview Question 🔥 - th-cam.com/video/eBTBG4nda2A/w-d-xo.html Kaisa laga video? Are you feeling excited? Let me know in the comments below. ❤️
Thank you, it is a great help, I am preparing for the interview for the role of a frontend developer. I was waiting for this topic for so long since you have covered it is a great help.
I've completed my master's in mechanical enginnering, and after that, I planned to switch my career in the IT industry. Yesterday, I cracked the first round of interviews for the position of front-end developer. All the questions on JS were from your videos, and I can bet that the interviewer has also watched your Namaste Javascript series.
A closure gives access to all the variables of it's parent function even after the that parent function has returned or executed. The function keeps a refernce to it's outer scope which preserves the scope chain throughout the time
Mainly closures & this keyword helped me land a great new job. Thanks Akshay for creating such a great course (Namaste JS Season 1 & 2). I recommend this series to everyone as a prerequisite towards their frontend job search.
Things learned: 1. Function bundled with lexical scope is called closure. 2. Even if we return the function, it still remembers its original lexical environment and local storage so it can access values. 3. If we write return function x(){.....} --- this automatically returns the value. 4. The function that is returned is reference so any change in value of that variable inside function will be reflected as such.
i am backend developer and just started to explore frontend tools. No one can explain javascript better then you Sir. all the best, stay healthy and help us all junior developers to learn complicated things. Thanks .
i feel the Same too in 2024 now.even though this video got 3 years old.i also feel the same .Let's GET DEEP DIVE INTO THIS.........................................
Never read or tried to learn JavaScript... But, Started directly to work on it and it's been almost 8 years.. Now these videos are making me realize , why I struggled with those setTimeout n all ..
Hi akshay, after complete the Namaste js playlist, please make a playlist for Namaste react. Tons of video out there for react, but your teaching will be easy to grab the core concepts. It's our kind request 🙏...
Voting for React and also for Node.JS and other backend technologies since this man is the only instructor that I have found who cares enough to go in depth and also show behind the scenes kind of stuffs.
Bro!! two days back JS is a horror movie for me, now I started liking JS more, lexical scope video is awesome...thanks for your efforts, I like the way how you explain. Credit goes to you.
One of the finest JavaScript tutorials available, it showcases the art of a talented teacher who effortlessly breaks down complex concepts into easily understandable content.
i feel like that the creation phase/execution conext is like one of the most crucial concept in js... nearly everything is explainable by creationphase/hoisting and the scopes
Today i have seen this chapter and attended an interview. I had a question about closure and i was so excited to answer it, done it successfully but the 2nd question in closure was let scope function a (){
function b{ let x = 3; } function c{ let y = 4; } function d{ console.log(x,y) } } now how to change this code to access the x and y variables inside d(), I simply told change let to var, but the suggested answer was we can write like below function a (){ function b{ let x = 3; function c{ let y = 4; function d{ console.log(x,y) } } } } However, this helps me lot. :)
I am doing a full stack developer course online and my mentor suggested your videos.Your videos gave me a lot of new ideas and get to know javascript in depth.Thanks Akshay for your efforts 🙏
Topics should be covered. It can help the whole javascript community and me ofcourse. 1. Promises 2. async/await 3. callbacks 4. Polymorphism and inheritance in javascript 5. Memoization 6. Prototype
I have been watching his videos in incognito (just the way I am), and didn't even think of liking videos and stuff. but the moment of GREEN TEA. Man, that literally made me open the video in main window, just to comment this. Akshay, you never fail to make videos interesting, be with the kind of energy you put into and the way of explaining things. Nice work. Green Tea man. LOL.
this is more worth than any tutorials i am sure i got placement for a angular developer in a company they also asked me javascript questions i am sure everyone who is learning this course it's worth always remember react or angular it's just a library of javascript javascript is the main thing learn that deeply like akshay saini tell you all the best thank you akshay love you i am 19 years old now
First time landed to your channel in my journey of two years learning and development and I really appreciate the way you explain I was searching for closure and have read blogs watched videos things was clear to me but I was seeking a good definition and you provided it. then explained it very well through the example. Keep it up. Wish you great luck for your future,
11:25 I am watching js video along with some cool drama show 🤣🤣. I was watching your video because of js and my sister in class 10 was watching you because of your funny expression.
I used to be this mush excited about javascript, but now i am kinda stuck with .net core for a while. But i absolutely love javascript and closures. watched this videos because of the good old memories. Nostalgic!! Still remember the way i explained it to my juniors
Really explained well. I love the enthusiasm of your explanation and your expressions. Really excited for next video. Requesting to cover the topics of generators, iterators.
Wow. Great explanation. I understood the concept very well. It seems easy for me bkz this is the first time am learning Closures and JS. Glad I started learning JS through your videos. I strongly fell that I saved a lot of time while gaining strong knowledge in JS.
Woah... I have watched numerous videos on closure. Looking at the 20+ mins duration made me reluctant at first. Halfway through the video and looks like I'm finally able to understand this topic. THANK YOU BROTHER ♥
I was trying to get this concept since morning by roaming here and there, saw many videos even in hindi which is our mother language and came across your video, and trust me i got it at once😍😍, I didn't had to play your video again and again, it's just your way of teaching is literally awesome and now I got a mentor... Thank you so much man,🥰 All i can feel is if a person could understand english language and still doesn't get what javascript really is by your videos, he/she is not meant for coding.
i am learning js from last 1 year but never understand js in so much depth. Now i can say that i am good in js and have depth knowledge of it. All thanks to you 🥰
You are an outstanding Guru !!! Before watching this video, I had watched 5,6 videos but could not understand anything, but you made me know this within minutes! You are a genius!!
How tough the subject is. Its not a matter. If we find a good master. We can make it! Akshay a legend! My master u r! I m learning js. One day definitely will get a job.i will put in this comment box.credits to u master!
Yes I will able to give answer in my interview now ... when we have returned function it not just the function code return but a closure enclosed alongwith lecxical scope will returned. Closure: Function alongwith it's lexical scope forms a closure i.e., known as Closure ❤
Watching it for second time , with same amount of satisfraction , Your teaching way if so unique that , Your definations just hit the mid point of the brain which saves the content automatically !
Hello, thank you for this mind blowing series! I've a doubt regarding closures. Here's my very brief explanation of closures. - A Closure "space" is created, apart from the Execution Context, whenever a reference to any variable or function is made from an inner function, so that even the EC of outer function goes out of scope, we've access to the required variables. So It contains the function bundled with the lexical env. My doubt is regarding the "space", I don't exactly understand what a closure is physically in memory. Is like an execution context or just a separate space or something else. Once again thanks a lot for this amazing content.
We can assume it to be a separate space in the memory, because we know that variables are stored in memory spaces. And, for sure it is not an execution context. Just like in the memory space we have different sections like - global, local (you must have observed this when a functional execution context is created), script (for hoisting let and const declarations), in the same way closure is also a separate memory space.
I regularly take interviews, give interviews, I have event watched the entire Namaste JS series multiple times. Still came to this video like 10th may be 12th time to revise closures. This is highly satisfying knowledge. Thanks a lot @Akshay. More power to you :)
Loved the video! Closure definition: a function bound together with its lexical environment. This means an inner nested function has access to its parents' lexical scope, and is able to remember variables the were declared in that environment, even after that functions has been removed from the call stack. You did a very good job of explaining this. I think I've got a ways to go before I totally understand all this stuff though :P
Thank-you Akshay. I love watching your videos. You are first and last my favourite instructor of js. Please keep making videos on js advance. I was watching my instructor video around 3 hours but didn't understand not even a single line but when I learnt from you. I understood easily. Kindly cover oops LLD Promise Fetch api these kind of topics too. So that we all be good at programing like you.🙏🙏🙏🙏🙌🙌🙌🙌🙌❤️❤️❤️🎉
I'm thoroughly enjoying learning from your Namaste Javascript series! Your videos are incredibly helpful, and I'd love to see more of them. Could you please consider creating a series on Namaste Angular as well? It would be fantastic to delve deeper into this topic with your guidance!
you are probably the only person on youtube with a video on closures who actually knows what closures are, kudos my fellow developer! I just want to add, for what it's worth, two things that might be important to understand when doing functional programming in JS: 1. Closures are bound to the function upon it's declaration. this is what allows them to be returned and have their lexical scope persist after the function that contained them is no longer alive. 2. Closures only close over their most immediate lexical scope. in the case of your function y(), it is only responsible for creating Closure (x), not Closure (z)... that was created when function x() was declared. the thing is, since closures are themselves lexical scopes, and are mixed into the lexical scope of the function they are declared with upon its invocation, Closure (z) gets passed to y() when it gets invoked through it's own Closure (x). This last distinction is very important, as the creation of multiple closures over z() could potentially create multiple versions of b - with different values - if, for example, y were an object with 2 functions, each with a separate closure and a body that manipulated b. It would also make it much harder for the garbage collector to determine when a scope was no longer being used, as it would have to keep track the immediage lexical closures, and any other closures created inside said closures, and so on and so forth. I'm only adding this because I think you did a marvellous job of explaining this topic, and want to complement the information you already put forth.
This is one of the most enlightening comments I’ve got on my videos. It goes even more deep when understanding Closures. Thank you so much, Nicolas. ♥️
I watched 3 videos to understand closures and I was lost, but finally understood here, the way you covered every single thing... It is really very helpful. Thank you!
"Microservices architechture", I think you should cover this, reason being most of us are very confused about what it actually is, how to use it and where??
Kudos for explaining this important concept. But mentioning things like y remembers the reference of a is vague, better will be to mention how a is stored in memory and how y is able to acess that reference outside x.
The most amazing thing in Sir Akshay is he explain the exact meaning of each term and usage in coding ,that most developer dont even noticed these things they Just clear how they work but dont know the exact background of each term,And here Sir explain both So Bundle of thanks Sir je
For revision : Q)What is closure? A)The function bundled with its lexical environment closed to that function simply function + Lexical environment and closures have very special place in runtime environment The fun in JavaScript is you can assign a variable for a function and also you can pass function as a parameter even you can return the function in JavaScript!! Myself : th-cam.com/video/74hA6Q7vPI4/w-d-xo.html Q)What does the closure do in my JavaScript programs? A) Whenever I call a function in JavaScript the closure maintains its values(lexical env.) and function in its own runtime and when that specific function executed, it returns with own environment even the variable vanished after its execution 11:36 : Simaran! because is on Diet 13:54 : as variable value is changed before executing the return (the function) Value will be 100 In closures, values in variable are 'pass by reference' hence there values can be changed, and whenever comes the closure inside closure(multilevel one) we can see the function refers the 'parent' variable My Response 21:38
@@pekalarajesh6147 Since the assignment of the value '100' was after the declaration of the function 'y', but was before the actual function call. When the function 'x' was executed, the assignment 'a = 100' was processed, and the reference to 'a' is what persists, not the actual value at 'a'.
The way you explain it seems the js is in your nerves and it's flowing. It also seems you are teaching yourself, I have seen many videos regarding JS but no one tried and dedicatedly explained the way you are. Keep growing, learning and teaching.
UPDATE : SERIOUSLY GOT A JOB BECAUSE OF THIS ! NOT KIDDING THIS TIME ! Went to an interview. Interviewer: Write an example of closure. Me: Wrote down this example Interviewer: Namaste Javascript ? 🤨 Me: 😐 Interviewer: Even I have the same example in mind. High five'd each other. Happily working ever after 🥳🥳🥳
A function along with its lexical environment forms a closure. Lexical scope means the references that function was associated with, which means that whenever a function forms a closure it is bound to remember the references it was created with initially(the part in the code where it is called does not matters in case of closures )
Bahut jgh pdha..mdn v dekha tha utne acche se ni smjh aaya but yha full clear hua bhut acche se . Ab refrence aapka v lunga js related.dhywaad aur bhgwaan aapko aise hi aage badhate aur khus rakhe ❤️
yesterday i had interview and he ask me closure i was not able to answer him, now i can explain anyone thanks akshay..............kash ye video pehle dekh liya hota
Things Learned: 1. Function bundled with its lexical environment is known as a closure. 2. Whenever function is returned, even if its vanished in execution context but still it remembers the reference it was pointing to. Its not just that function alone it returns but the entire closure and that's where it becomes interesting.
it was really an amazing video on closure, before watching this video I was struglling to find out what exactly is closure. But now I can confidently say that this is what it need to bee... Thank you bhai for this wonderful video...
00:02 Closures in JavaScript 02:58 Closures in JavaScript are functions bundled together with their lexical environment. 05:45 Closures in JavaScript 08:42 Closures in JavaScript are powerful and allow functions to access variables from higher scopes. 11:20 Understanding closures in JavaScript 14:51 Closures in JavaScript can be tricky to understand. 18:10 Closures in JavaScript are powerful and essential for designing patterns and functions. 20:35 Closures in JavaScript are powerful and essential for understanding advanced concepts. 02:58 Closures in JavaScript are functions bundled together with their lexical environment. 05:45 Closures in JavaScript 08:42 Closures in JavaScript are powerful and allow functions to access variables from higher scopes. 11:20 Understanding closures in JavaScript 14:51 Closures in JavaScript can be tricky to understand. 18:10 Closures in JavaScript are powerful and essential for designing patterns and functions. 20:35 Closures in JavaScript are powerful and essential for understanding advanced concepts.
Literally got goosebumps at some point when the concept was so much well explained by you and so well understood by me! Awesome way of explaining things man :D . Also when you requested to give a like on this video, thought If I could contribute some money for your videos because these videos reaching to me without any cost(sorry for adBlocker) is pretty undigestable.
Closure :Function bundled with its lexical environment is known as a closure. Whenever function is returned, even if its vanished in execution context but still it remembers the reference it was pointing to. Its not just that function alone it returns but the entire closure and that's where it becomes interesting !! Thank you so much, Akshay for this :) :)
Thanks
Buddy, was it necessary to be rude?
You put it in beautiful words
@@pranjalrathod2158 rude? Who?
@@sss-kd9md that guy deleted the comment now. Let's ignore
Four things I like about Akshay.
1) Doesn't try and speak in an American accent, like most Indian TH-cam programmers.
2) Passionate
3) Someone with real knowledge.
4) A talented teacher.
Love you! ♥️
hes very authentic,first time i thought he was quite weird owing to the fact that im not indian but now i cant get enough of his content
That's what make him unique!
you mean Hitesh choudhary ?
@@us-xf3kk 🤣
Next Video: setTimeout + Closures Interview Question 🔥 - th-cam.com/video/eBTBG4nda2A/w-d-xo.html
Kaisa laga video? Are you feeling excited? Let me know in the comments below. ❤️
awesome video, earlier for long i am running from JS but now truly i am enjoying learning JS and exploring more, tons of thanks to you...
Thank you, it is a great help, I am preparing for the interview for the role of a frontend developer.
I was waiting for this topic for so long since you have covered it is a great help.
Jhakaas jhakaas jhakaas
Great. The way you teaching is Great.
Amazing and very detailed as always..😊😊
I've completed my master's in mechanical enginnering, and after that, I planned to switch my career in the IT industry.
Yesterday, I cracked the first round of interviews for the position of front-end developer.
All the questions on JS were from your videos, and I can bet that the interviewer has also watched your Namaste Javascript series.
Wow😂 bro..
Congratulations, Faraz. You’re inspiration to many! ♥️
@@akshaymarch7 Thanks bro. I've joined that company on 6th September. Apart from that, I got one more offer as front-end developer.
@@farazhusain925 i m looking for job as front end developer can you help me how to find it
@@farazhusain925 I am also looking for job as front end developer recently I have completed HTML CSS and JavaScript presently i am learning reactjs
Rest of the world : JS is hard and crazy
Akshay : hold my green tea.
Hitesh: Hold my ice tea.
@@AmrithMS travery media....are u challenging me?
@@Oldstoryhouse the new Boston..... focking noobs
javascript is the most beautiful language and typescript is legendary with those types
@@Oldstoryhousep
My interviewer got impressed when I explained the way you explained. Dude you are a 💎.
Wohooo! ✌️😎
For which role you applied?
A closure gives access to all the variables of it's parent function even after the that parent function has returned or executed. The function keeps a refernce to it's outer scope which preserves the scope chain throughout the time
Mainly closures & this keyword helped me land a great new job. Thanks Akshay for creating such a great course (Namaste JS Season 1 & 2). I recommend this series to everyone as a prerequisite towards their frontend job search.
Wish you the best, keep rising! 🚀
Bhaiya is high on JS 😂. More power to you.
Haha !! So much passion for Javascript . Great !
Indeed! :D
Closures is another level
High on Javascript and green tea....Snoop Dogg no match xD
Exactly..
Things learned:
1. Function bundled with lexical scope is called closure.
2. Even if we return the function, it still remembers its original lexical environment and local storage so it can access values.
3. If we write return function x(){.....} --- this automatically returns the value.
4. The function that is returned is reference so any change in value of that variable inside function will be reflected as such.
bro is everywhere Thank you for this notes.
One step closer to Closure.
Thank you Akshay, I cleared my JS interview because of your videos only.
Congratulations, brother! ❤️
I am beginner please give some tips
@@akshaymarch7 comment testing
As a Mechanical Engineer, I'm really enjoying this course. The way you are explaining is simply superb.
i am backend developer and just started to explore frontend tools. No one can explain javascript better then you Sir. all the best, stay healthy and help us all junior developers to learn complicated things. Thanks .
Man how can a student not be excited if the teacher himself is so so much excited. Great video bro
this dude makes me fall in love with JS. And, yes. i'll never have to find another video on closures. thanks a million!
i feel the Same too in 2024 now.even though this video got 3 years old.i also feel the same .Let's GET DEEP DIVE INTO THIS.........................................
Never read or tried to learn JavaScript...
But, Started directly to work on it and it's been almost 8 years..
Now these videos are making me realize , why I struggled with those setTimeout n all ..
Hi akshay, after complete the Namaste js playlist, please make a playlist for Namaste react. Tons of video out there for react, but your teaching will be easy to grab the core concepts. It's our kind request 🙏...
JavaScript itself is vast, but yeah once he completes that...may be he can put a udemy course for React.
😀
That would be awesome!
Vote for reactjs :D
Voting for React and also for Node.JS and other backend technologies since this man is the only instructor that I have found who cares enough to go in depth and also show behind the scenes kind of stuffs.
Yes pleaseeee
Bro!! two days back JS is a horror movie for me, now I started liking JS more, lexical scope video is awesome...thanks for your efforts, I like the way how you explain. Credit goes to you.
Bhaiya, Please don't ever delete this playlist!!!..This is super helpful and helps me revise it before the interview!!!!
One of the finest JavaScript tutorials available, it showcases the art of a talented teacher who effortlessly breaks down complex concepts into easily understandable content.
Another seriously underrated JS channel. Clear and simple explanation. Thank you Namaste :)
can u tell us more underrated JS channels.
i feel like that the creation phase/execution conext is like one of the most crucial concept in js... nearly everything is explainable by creationphase/hoisting and the scopes
Brooo never seen anyone teaching online with that excitement!!! This is soo good! the content and the learning :))
Your content is gold. Everytime I need to brush up any concepts I go through the videos on your channel. You are awesome!!!!
Damn bruh! It got aggressive real quick!!!
Reminds me of that Maths teacher yelling at the screen 😂
Haha, that math teacher was my favorite. 😂
haha! bhut sahi
Studied JS from alot of resources but this man made me fall in love with it , a true guru 🙏🏻, just remarkable
Today i have seen this chapter and attended an interview. I had a question about closure and i was so excited to answer it, done it successfully but the 2nd question in closure was let scope
function a (){
function b{
let x = 3;
}
function c{
let y = 4;
}
function d{
console.log(x,y)
}
}
now how to change this code to access the x and y variables inside d(), I simply told change let to var, but the suggested answer was we can write like below
function a (){
function b{
let x = 3;
function c{
let y = 4;
function d{
console.log(x,y)
}
}
}
}
However, this helps me lot. :)
Changing let to var will not work as var is 'function scoped' so we cannot access it outside the function.
I am doing a full stack developer course online and my mentor suggested your videos.Your videos gave me a lot of new ideas and get to know javascript in depth.Thanks Akshay for your efforts 🙏
Topics should be covered. It can help the whole javascript community and me ofcourse.
1. Promises
2. async/await
3. callbacks
4. Polymorphism and inheritance in javascript
5. Memoization
6. Prototype
All of these are coming!! 💥
@@akshaymarch7 we are waiting for these topics
@@akshaymarch7 i am also eagerly waiting for those topics
@@akshaymarch7 waiting please upload the videos as soon as possible plz bro
@Akshay Sani . Waiting for these too :)
I have been watching his videos in incognito (just the way I am), and didn't even think of liking videos and stuff. but the moment of GREEN TEA. Man, that literally made me open the video in main window, just to comment this. Akshay, you never fail to make videos interesting, be with the kind of energy you put into and the way of explaining things. Nice work. Green Tea man. LOL.
These videos are amazing. Its the depth, the enthusiasm, the great explainations etc….
this is more worth than any tutorials i am sure i got placement for a angular developer in a company they also asked me javascript questions i am sure everyone who is learning this course it's worth always remember react or angular it's just a library of javascript javascript is the main thing learn that deeply like akshay saini tell you all the best thank you akshay love you i am 19 years old now
I have nothing to do with JS, and yet I am watching this as if my life thrives upon it.
Going great like always! 🤗🤗
Thank you so much, Simran 🤗
First time landed to your channel in my journey of two years learning and development and I really appreciate the way you explain I was searching for closure and have read blogs watched videos things was clear to me but I was seeking a good definition and you provided it. then explained it very well through the example. Keep it up. Wish you great luck for your future,
11:25 I am watching js video along with some cool drama show 🤣🤣. I was watching your video because of js and my sister in class 10 was watching you because of your funny expression.
Hahaha 😂
Ask her to subscribe for more drama. 😂
I used to be this mush excited about javascript, but now i am kinda stuck with .net core for a while. But i absolutely love javascript and closures. watched this videos because of the good old memories. Nostalgic!! Still remember the way i explained it to my juniors
Really explained well. I love the enthusiasm of your explanation and your expressions. Really excited for next video. Requesting to cover the topics of generators, iterators.
Wow. Great explanation. I understood the concept very well. It seems easy for me bkz this is the first time am learning Closures and JS. Glad I started learning JS through your videos. I strongly fell that I saved a lot of time while gaining strong knowledge in JS.
If the video would have been 3 hours long I would have seen it with full enthusiasm.
Thanks Akshay sir.
Keep posting.
❤️
Woah... I have watched numerous videos on closure. Looking at the 20+ mins duration made me reluctant at first. Halfway through the video and looks like I'm finally able to understand this topic.
THANK YOU BROTHER ♥
Akshay Saini is on a mission to make all of us great at JS. Thank you so much man
I was trying to get this concept since morning by roaming here and there, saw many videos even in hindi which is our mother language and came across your video, and trust me i got it at once😍😍, I didn't had to play your video again and again, it's just your way of teaching is literally awesome and now I got a mentor... Thank you so much man,🥰 All i can feel is if a person could understand english language and still doesn't get what javascript really is by your videos, he/she is not meant for coding.
Really love your energy! Your content is really helping with my interviews!!
i am learning js from last 1 year but never understand js in so much depth. Now i can say that i am good in js and have depth knowledge of it. All thanks to you 🥰
Only Legends would Binge watch This series😎 #JS😘😀😁
Coding from last 11 years and never seen this beauty of JS. Thank you so so much 💖
Finally, today I can sleep peacefully. We won over closure after watching this video. 😅
You are an outstanding Guru !!! Before watching this video, I had watched 5,6 videos but could not understand anything, but you made me know this within minutes! You are a genius!!
How tough the subject is. Its not a matter. If we find a good master. We can make it! Akshay a legend! My master u r! I m learning js. One day definitely will get a job.i will put in this comment box.credits to u master!
Yes I will able to give answer in my interview now ... when we have returned function it not just the function code return but a closure enclosed alongwith lecxical scope will returned.
Closure: Function alongwith it's lexical scope forms a closure i.e., known as Closure ❤
Best video on CLOSURE...the energy level and the content🔥🔥🔥...thanks a lot..😎😎
Watching it for second time , with same amount of satisfraction , Your teaching way if so unique that , Your definations just hit the mid point of the brain which saves the content automatically !
You make complex topics feel like a "Hello World" program 🙏. You truly have a knack for teaching.
Hello, thank you for this mind blowing series!
I've a doubt regarding closures. Here's my very brief explanation of closures.
- A Closure "space" is created, apart from the Execution Context, whenever a reference to any variable or function is made from an inner function, so that even the EC of outer function goes out of scope, we've access to the required variables. So It contains the function bundled with the lexical env.
My doubt is regarding the "space", I don't exactly understand what a closure is physically in memory. Is like an execution context or just a separate space or something else.
Once again thanks a lot for this amazing content.
We can assume it to be a separate space in the memory, because we know that variables are stored in memory spaces. And, for sure it is not an execution context. Just like in the memory space we have different sections like - global, local (you must have observed this when a functional execution context is created), script (for hoisting let and const declarations), in the same way closure is also a separate memory space.
I regularly take interviews, give interviews, I have event watched the entire Namaste JS series multiple times. Still came to this video like 10th may be 12th time to revise closures. This is highly satisfying knowledge. Thanks a lot @Akshay. More power to you :)
🚀🚀🚀
@@akshaymarch7 Checking nested comments on youtube
Loved the video! Closure definition: a function bound together with its lexical environment. This means an inner nested function has access to its parents' lexical scope, and is able to remember variables the were declared in that environment, even after that functions has been removed from the call stack.
You did a very good job of explaining this. I think I've got a ways to go before I totally understand all this stuff though :P
Thank-you Akshay. I love watching your videos. You are first and last my favourite instructor of js. Please keep making videos on js advance. I was watching my instructor video around 3 hours but didn't understand not even a single line but when I learnt from you. I understood easily.
Kindly cover
oops
LLD
Promise
Fetch api these kind of topics too. So that we all be good at programing like you.🙏🙏🙏🙏🙌🙌🙌🙌🙌❤️❤️❤️🎉
I'm thoroughly enjoying learning from your Namaste Javascript series! Your videos are incredibly helpful, and I'd love to see more of them. Could you please consider creating a series on Namaste Angular as well? It would be fantastic to delve deeper into this topic with your guidance!
The excitement level is the dam high
I was looking for this comment, checking whether it mee or someone else also thinking the same 😂♥️
@@mohit96nain yo bro 🤣
@@mohit96nain mee too, thinking of it same 😅
you are probably the only person on youtube with a video on closures who actually knows what closures are, kudos my fellow developer!
I just want to add, for what it's worth, two things that might be important to understand when doing functional programming in JS:
1. Closures are bound to the function upon it's declaration. this is what allows them to be returned and have their lexical scope persist after the function that contained them is no longer alive.
2. Closures only close over their most immediate lexical scope. in the case of your function y(), it is only responsible for creating Closure (x), not Closure (z)... that was created when function x() was declared. the thing is, since closures are themselves lexical scopes, and are mixed into the lexical scope of the function they are declared with upon its invocation, Closure (z) gets passed to y() when it gets invoked through it's own Closure (x).
This last distinction is very important, as the creation of multiple closures over z() could potentially create multiple versions of b - with different values - if, for example, y were an object with 2 functions, each with a separate closure and a body that manipulated b. It would also make it much harder for the garbage collector to determine when a scope was no longer being used, as it would have to keep track the immediage lexical closures, and any other closures created inside said closures, and so on and so forth.
I'm only adding this because I think you did a marvellous job of explaining this topic, and want to complement the information you already put forth.
This is one of the most enlightening comments I’ve got on my videos. It goes even more deep when understanding Closures. Thank you so much, Nicolas. ♥️
I was waiting for this since long 😃 Today I will sleep well ✨
True.
Me2😀
Wow amazing bro....
Same here...!! Excited..!!!
I want to say we love you man! Thank you for all the efforts and time you devote to making awesome videos like this.
Namasty Bro. I think you're impacting more knowledge than most schools🙏🙏🙏
I watched 3 videos to understand closures and I was lost, but finally understood here, the way you covered every single thing... It is really very helpful. Thank you!
"Microservices architechture", I think you should cover this, reason being most of us are very confused about what it actually is, how to use it and where??
Thank you so much bro!!! I've watching so many videos and reading articles and this is the one that sticks!! I can't believe it was just that simple!
Kudos for explaining this important concept.
But mentioning things like y remembers the reference of a is vague, better will be to mention how a is stored in memory and how y is able to acess that reference outside x.
Nice point
The most amazing thing in Sir Akshay is he explain the exact meaning of each term and usage in coding ,that most developer dont even noticed these things they Just clear how they work but dont know the exact background of each term,And here Sir explain both
So Bundle of thanks Sir je
Vinoth love❤️ >> Akshay:
One thing i forgot to inform bro dress code And hairstyle is awesome
And finally End music is Vera level :)
Probably the most concise explanation of closures. Awesome teaching!
For revision :
Q)What is closure?
A)The function bundled with its lexical environment closed to that function
simply function + Lexical environment
and closures have very special place in runtime environment
The fun in JavaScript is you can assign a variable for a function and also you can pass function as a parameter even you can return the function in JavaScript!!
Myself : th-cam.com/video/74hA6Q7vPI4/w-d-xo.html
Q)What does the closure do in my JavaScript programs?
A) Whenever I call a function in JavaScript the closure maintains its values(lexical env.) and function in its own runtime and when that specific function executed, it returns with own environment even the variable vanished after its execution
11:36 : Simaran! because is on Diet
13:54 : as variable value is changed before executing the return (the function) Value will be 100
In closures, values in variable are 'pass by reference' hence there values can be changed, and whenever comes the closure inside closure(multilevel one) we can see the function refers the 'parent' variable
My Response 21:38
@0xFOXHOUND
hello bro can u please explain me why we got the value as 100...not 7
at 13:30
@@pekalarajesh6147 Since the assignment of the value '100' was after the declaration of the function 'y', but was before the actual function call. When the function 'x' was executed, the assignment 'a = 100' was processed, and the reference to 'a' is what persists, not the actual value at 'a'.
Oh my godd....I fell in love with his explanations of the closure concept. The way he explains the clouse concept was top notch😍
I have watched 1000 videos before this and i can guarantee you i will not watch again any video of closure again . Thanks Akshay
The way you explain it seems the js is in your nerves and it's flowing. It also seems you are teaching yourself, I have seen many videos regarding JS but no one tried and dedicatedly explained the way you are. Keep growing, learning and teaching.
UPDATE : SERIOUSLY GOT A JOB BECAUSE OF THIS ! NOT KIDDING THIS TIME !
Went to an interview.
Interviewer: Write an example of closure.
Me: Wrote down this example
Interviewer: Namaste Javascript ? 🤨
Me: 😐
Interviewer: Even I have the same example in mind.
High five'd each other. Happily working ever after 🥳🥳🥳
hahha
Hahaha😂😂
A function along with its lexical environment forms a closure. Lexical scope means the references that function was associated with, which means that whenever a function forms a closure it is bound to remember the references it was created with initially(the part in the code where it is called does not matters in case of closures
)
Getting to learn a lot. Thank you so much for sharing your knowledge . This course is helping me a lot.
Bahut jgh pdha..mdn v dekha tha utne acche se ni smjh aaya but yha full clear hua bhut acche se . Ab refrence aapka v lunga js related.dhywaad aur bhgwaan aapko aise hi aage badhate aur khus rakhe ❤️
He literally treats people who learn other languages as aliens! :D Indeed JS is beautiful.
I love Aliens. ❤️
@@akshaymarch7 i love AYushi
@@currentadda7884 bhai chill lol
yesterday i had interview and he ask me closure i was not able to answer him, now i can explain anyone thanks akshay..............kash ye video pehle dekh liya hota
Chitvan(Hope you know the legend): Baba, you are beautiful
Akshay: JavaScript, you are beautiful 😃
I am learning Javascript for Test automation and I am really happy to learn it from basics and how its works internally.
Me (30 mins before interview) - Note that, note that!!!
Mujhe Closure kisi aise hi passionate instructor se samjh aa sakta tha.....Thanks man
Things Learned:
1. Function bundled with its lexical environment is known as a closure.
2. Whenever function is returned, even if its vanished in execution context but still it remembers the reference it was pointing to. Its not just that function alone it returns but the entire closure and that's where it becomes interesting.
it was really an amazing video on closure, before watching this video I was struglling to find out what exactly is closure. But now I can confidently say that this is what it need to bee...
Thank you bhai for this wonderful video...
Dude, nice hairstyle and video.
Man!!! I like how you are passionate about closure, I wasn't planning to watch the next video, but I will now
It wasn't a green tea, it was a cocktail of JS pills, cocaine, and steroids. The man is on a killing spree in this video. Great fuckin' work!
People say communication is the key trait of growth and everything and I could see it today in this session! need to work on it bruh!
Senior and cool developers disliked the video because they still didnt get it !
😅
best video series I have ever seen about javascript and it's peculiarities. thank you Akshay Saini!
10:45 😂😂😂😂😂
Hahaha 😂
Prior to this video, I was expecting closure a rocket science, but Akshay made it so simple. Just amazing
1:30 you sounded like Arnab Goswamy
Hahaha 😂 😂
00:02 Closures in JavaScript
02:58 Closures in JavaScript are functions bundled together with their lexical environment.
05:45 Closures in JavaScript
08:42 Closures in JavaScript are powerful and allow functions to access variables from higher scopes.
11:20 Understanding closures in JavaScript
14:51 Closures in JavaScript can be tricky to understand.
18:10 Closures in JavaScript are powerful and essential for designing patterns and functions.
20:35 Closures in JavaScript are powerful and essential for understanding advanced concepts.
02:58 Closures in JavaScript are functions bundled together with their lexical environment.
05:45 Closures in JavaScript
08:42 Closures in JavaScript are powerful and allow functions to access variables from higher scopes.
11:20 Understanding closures in JavaScript
14:51 Closures in JavaScript can be tricky to understand.
18:10 Closures in JavaScript are powerful and essential for designing patterns and functions.
20:35 Closures in JavaScript are powerful and essential for understanding advanced concepts.
17:05 : "If I call my x"
Bruh been calling her ,she doesn't pick up, what to do😭😭
hahahha
Literally got goosebumps at some point when the concept was so much well explained by you and so well understood by me! Awesome way of explaining things man :D . Also when you requested to give a like on this video, thought If I could contribute some money for your videos because these videos reaching to me without any cost(sorry for adBlocker) is pretty undigestable.
You are diamond 💎 sir with no doubt .continue this way teaching .I never boarded with your series
the moment you said "you will love this" at 3:45s and the expression you gave, that felt like i am really gonna love this :p