C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
.NET
ADO.NET
Android
ASP.NET
C#
Databases & DBA
Design Patterns & Practices
iOS
Java
OOP/OOD
SharePoint
Software Testing
Web Development
WPF
View All
2
Reply
What are Javascript closures? Explain its Uses?
Atul Jain
13y
1.6k
0
Reply
Delete Row
Delete Column
Insert Link
×
Insert
Cancel
Embed YouTube Video
×
Width (%)
Height (%)
Insert
Cancel
Table Options
×
Rows
Columns
First row as header
Create Table
Insert Image
×
Selected file:
Alignment
Left
Center
Right
Select an image from your device to upload
Upload to Server
Cancel
Submit
A closure is a pairing of a function along with its referencing environment such that identifiers within the function may refer to variables declared within the referencing environment.It's an inner function that has access to the outer (enclosing) function's variables—scope chain. The closure has three scope chains: it has access to its own scope (variables defined between its curly brackets), it has access to the outer function's variables, and it has access to the global variables.function showName (firstName, lastName) {? ?var nameIntro = "Your name is ";// this inner function has access to the outer function's variables, including the parameter? ?function makeFullName () {? ?return nameIntro + firstName + " " + lastName;? } ? ?return makeFullName ();? }? ? showName ("Michael", "Jackson"); Closures can be used to accomplish many things. They are very useful for things like configuring callback functions with parameters.Closures are useful when used in conjunction with the setTimeout() and setInterval() functions.
Abhay Shanker
11y
0
A closure is an inner function that has access to the outer (enclosing) function's variables as well as its own.You can use closures to implement encapsulation something like this,a = (function () {var privatefunction = function () {alert('hello');}return {publicfunction : function () {privatefunction();}} })();
Jaganathan Bantheswaran
11y
0
What is the difference between window.onload and onDocumentReady in JavaScript?
What are the different Data Types are supported by JavaScript?
Message