Premium Only Content
 
			Learn JavaScript CLOSURES in 10 minutes! 🔒
// closure = A function defined inside of another function,
// the inner function has access to the variables
// and scope of the outer function.
// Allow for private variables and state maintenance
// Used frequently in JS frameworks: React, Vue, Angular
00:00:00 intro
00:00:31 example 1
00:02:19 example 2
00:07:00 example 3
00:10:08 conclusion
// ---------- EXAMPLE 1 ----------
function outer(){
const message = "Hello";
function inner(){
console.log(message);
}
inner();
}
message = "Goodbye";
outer();
// ---------- EXAMPLE 2 ----------
function createCounter() {
let count = 0;
function increment() {
count++;
console.log(`Count increased to ${count}`);
}
function getCount() {
return count;
}
return {increment, getCount};
}
const counter = createCounter();
counter.increment();
counter.increment();
counter.increment();
console.log(`Current count: ${counter.getCount()}`);
// ---------- EXAMPLE 3 ----------
function createGame(){
let score = 0;
function increaseScore(points){
score += points;
console.log(`+${points}pts`);
}
function decreaseScore(points){
score -= points;
console.log(`-${points}pts`);
}
function getScore(){
return score;
}
return {increaseScore, decreaseScore, getScore};
}
const game = createGame();
game.increaseScore(5);
game.increaseScore(6);
game.decreaseScore(3);
console.log(`The final score is ${game.getScore()}pts`);
- 	
				 1:02:27 1:02:27VINCE2 hours agoA Very Trump Halloween | Episode 159 - 10/31/25108K39
- 	
				 LIVE LIVEBadlands Media10 hours agoBadlands Daily: October 31, 20253,992 watching
- 	
				 1:34:28 1:34:28Graham Allen3 hours agoSCARY: Kamala Had MELT DOWN Over Trump!! Does LSU Hate Charlie Kirk?! + Top Halloween Movies Of ALL TIME!!73.8K37
- 	
				 LIVE LIVECaleb Hammer1 hour agoShe Blames MAGA For Her Debt | Financial Audit233 watching
- 	
				 LIVE LIVEThe Big Migâ„¢3 hours agoWhat To Give The Man Who Has EVERYTHING!5,143 watching
- 	
				 1:32:16 1:32:16Benny Johnson2 hours agoSHOCK: Massive Food Stamp FRAUD Exposed: 59% of Welfare are Obese Illegal Aliens!? Americans RAGE…22K39
- 	
				 LIVE LIVEWendy Bell Radio7 hours agoAmerica Deserves Better6,241 watching
- 	
				 22:01 22:01DEADBUGsays2 hours agoDEADBUG'S SE7EN DEADLY HALLOWEENS14.6K5
- 	
				 LIVE LIVETotal Horse Channel13 hours ago2025 IRCHA Derby & Horse Show - October 31st41 watching
- 	
				 1:10:29 1:10:29Chad Prather15 hours agoStanding Holy in a Hostile World54.5K29