Skip to content
0:00 / 0:00

#javascript#closures#scope

Javascript Closure tutorial ( Closures Explained )

techsith

143K subscribers • 1 video on Hallway

YouTube
  • Recommended by 1 person: 1 on Stack Overflow and its sister sites.

Intermediate. Assumes working knowledge.

545K views10 years ago1 recommendation

Programming languagesJavaScript

An explanation of how closures and lexical scope work in JavaScript, demonstrating the difference between var and let in loops.

What are closures in javaScript and how and where to use them. So what is closure in javascript? "whenever you declare a function inside another function, the inside function(s) is/are recreated again each time the outside function is called" "Closures are functions that refer to independent (free) variables. In other words, the function defined in the closure 'remembers' the environment in which it was created." #JavaScript #closures #lexicalScope *My Udemy Courses udemy.com/js-masterclass/ *couponCode*=TECHSITH-9.99 udemy.com/course/react-hooks-course/?couponCode=TECHSITH-9.9… Follow me for technology updates * facebook.com/techsith * facebook.com/groups/techsith * twitter.com/techsith1 * linkedin.com/groups/13677140/ * medium.com/@patelhemil Help me translate this video. * youtube.com/timedtext_cs_panel?c=UCbGZKLIHpox2l0whz6_RYyg&ta… Note: use translate.google.com/ to translate this video to your language. Let me know once you do that so i can give you credit. Thank you in advance.

Why it's here

1 person recommends this

What people say. Recommended for understanding how JavaScript closures capture variables and how block-scoped let differs from var in loops.

Bimal Dason Stack Overflow • Recommends

On “How to ensure closures created in a loop capture the value of the loop variable from their particular iteration?”

We will check , what actually happens when you declare var and let one by one. Case1 : using var <script> var funcs = []; for (var i = 0; i < 3; i++) { funcsi = function () { debugger; console.log("My value: " + i); }; } console.log(funcs); </script> Now open your chrome console window by pressing F12 and refresh the page. Expend every 3 functions inside the array.You will see an property called [Scopes] .Expand that one. You will see one array object called "Global" ,expand that one. You will find a property 'i' declared into the object which having value 3. Conclusion: When you declare a variable using 'var' outside a function ,it becomes global variable(you can ch…