- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What are JavaScript Function Closures?
JavaScript function closure is the grouping of a function and where that function was declared. In JavaScript, all functions work like closures. A closure is a function uses the scope in which it was declared when invoked. It is not the scope in which it was invoked.
Here’s an example
<!DOCTYPEhtml> <html> <body> <h2>Working with JavaScript Closures</h2> <script> var num = 10; function a() { var num = 15; b(function() { alert(num); }); } function b(f) { var num = 30; f(); } a(); </script> </body> </html>

Advertisements