Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,195,493 members, 7,958,502 topics. Date: Wednesday, 25 September 2024 at 03:56 PM |
Nairaland Forum / Science/Technology / Programming / Understand Javascript Closures (422 Views)
To Those That Understand Javascript. / Pidgin English Tutorial: Understand Javascript Promise 1 / Understanding Closures In Javascript (2) (3) (4)
Understand Javascript Closures by pidginedtec(m): 5:41am On Aug 05, 2020 |
A closure is a function that remembers its outer variables and can access them. In JavaScript, closures are created every time a function is created. To see it in action, watch this video: https://www.youtube.com/watch?v=otNkXqcihpA |
Re: Understand Javascript Closures by engrjoshua: 12:50pm On Aug 05, 2020 |
Kudos. Love the concept of pidgin. We are Nigerians Keep it up broda 1 Like |
Re: Understand Javascript Closures by spartan117(m): 5:37pm On Aug 05, 2020 |
I have a question concerning closures. I wrote this function expression recently (first image), i expected it to return the inner function but it returned NaN. So i changed it to a function declaration (second image) and it returned the inner function just as i wanted. So my question is why did both functions behave differently with regards to closures. I know that there are little differences between function expressions and function declarations. Thanks
|
Re: Understand Javascript Closures by modash(m): 5:52pm On Aug 05, 2020 |
@spartan117 The issue is the one is an arrow function and the other isnt and arrow functions. Keeping in mind that arrow functions dont have the arguements keyword 3 Likes |
Re: Understand Javascript Closures by pidginedtec(m): 5:58pm On Aug 05, 2020 |
modash: Spot on! |
Re: Understand Javascript Closures by pidginedtec(m): 6:00pm On Aug 05, 2020 |
modash: In addition: Arrow functions do not have arguments binding. But they have access to the arguments object of the closest non-arrow parent function. |
Re: Understand Javascript Closures by pidginedtec(m): 6:02pm On Aug 05, 2020 |
Re: Understand Javascript Closures by spartan117(m): 7:19pm On Aug 05, 2020 |
modash:Ah I see! Thanks for this |
Re: Understand Javascript Closures by spartan117(m): 7:21pm On Aug 05, 2020 |
pidginedtec:Now i understand better. Thanks man 1 Like |
(1) (Reply)
Get Best Sitecore Training By Industry Experts At Cheap Price / FREE WEBINAR: Chatbot 101. Everything You Need To Know To Get Into Chatbots / 4 Most Important Features Of Transport Management System Software
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 10 |