From 7e30e1902d3f2c56ad7852d3c8b50e75510508df Mon Sep 17 00:00:00 2001 From: Abheek Samaddar Date: Sun, 26 Oct 2025 13:31:56 +0530 Subject: [PATCH 1/2] UPDATE README Closures examples --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/README.md b/README.md index 924a02f7..8c368529 100644 --- a/README.md +++ b/README.md @@ -848,6 +848,35 @@ The Event Loop is a critical part of JavaScript's concurrency model, ensuring no - [CLOSURES en JavaScript: Qué son y cómo funcionan - Carlos Azaustre](https://youtu.be/xa8lhVwQBw4) - [Learn Closures In 7 Minutes - Web Dev Simplified](https://www.youtube.com/watch?v=3a0I8ICR1Vg) + Here is a simple but efficient eample of javascript closures (Code):- + + //Counter function here + + function createCounter(){ + let count = 0; //private variable, can't be accessed outside this function + return { + increment: function(){ + count++; + console.log(`Count after increment: ${count}`); + }, + decrement: function(){ + count--; + console.log(`Count after decrement: ${count}`); + }, + getValue: function(){ + return count; + } + }; + } + + // now using this + const counter = createCounter(); // holding the function in another variable + counter.increment(); // Count after increment: 1 + counter.increment(); // Count after increment: 2 + counter.decrement(); // Count after decrement: 1 + console.log(`Final count: ${counter.getValue()}`); // Final count: 1 + + Wrapping up:- The data (here count) remains persistent and protected, while still it can be maipulated through controlled functions **[⬆ Back to Top](#table-of-contents)** From 627ce54a7154408f5e077cf908790df9b86546e1 Mon Sep 17 00:00:00 2001 From: Abheek Samaddar Date: Sun, 26 Oct 2025 13:57:13 +0530 Subject: [PATCH 2/2] ADDED LEARNING RESOURCE FOR Function Scope, Block Scope and Lexical Scope --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 8c368529..5f4a9c59 100644 --- a/README.md +++ b/README.md @@ -333,6 +333,9 @@ Lexical Scope: Refers to how variable access is determined based on the physical - [JavaScript Block scope vs Function scope - nivek](https://www.youtube.com/watch?v=IaTztAtoNEY) - [Lexical scoping in javascript - Hitesh Choudhary](https://www.youtube.com/watch?v=qT5S7GgIioE) - [Modern Scope Handling in JavaScript (ES6 and Beyond) -Prashant Dewangan ](https://www.youtube.com/watch?v=zMseUdOR7z8) +Additional Resource:- 📑💻 +- [Global and local scope in javascript | chai aur #javascript -Chai Aur Code ](https://youtu.be/cHHU0jXfjKY?si=jbMks9iRauJCYygC) +- [Lexical scoping and closures in javascript | chai aur #javascript -Chai Aur Code ](https://youtu.be/VaH09NXQZ58?si=eTX90Y81GvccMB_g) **[⬆ Back to Top](#table-of-contents)**