Skip to content

Commit

Permalink
closure added
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshchoudhary committed Jul 25, 2023
1 parent 9342c22 commit 4d27dc1
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions 11_fun_with_js/closure.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Closure aur chai</title>
</head>
<body style="background-color: #313131;">
<button id="orange">Orange</button>
<button id="green">Green</button>
</body>

<script>
// function init() {
// let name = "Mozilla";
// function displayName() {
// console.log(name);
// }
// displayName();
// }
// init();

// function outer(){
// let username = "hitesh"
// console.log("OUTER", secret);
// function inner(){
// let secret = "my123"
// console.log("inner", username);
// }
// function innerTwo(){
// console.log("innerTwo", username);
// console.log(secret);
// }
// inner()
// innerTwo()

// }
// outer()
// console.log("TOO OUTER", username);


// function makeFunc() {
// const name = "Mozilla";
// function displayName() {
// console.log(name);
// }
// return displayName;
// }

// const myFunc = makeFunc();
// myFunc();

</script>
<script>
// document.getElementById("orange").onclick = function(){
// document.body.style.backgroundColor = `orange`
// }
// document.getElementById("green").onclick = function(){
// document.body.style.backgroundColor = `green`
// }

function clickHandler(color){
// document.body.style.backgroundColor = `${color}`

return function(){
document.body.style.backgroundColor = `${color}`
}
}

document.getElementById('orange').onclick = clickHandler("orange")
document.getElementById('green').onclick = clickHandler("green")

</script>
</html>

0 comments on commit 4d27dc1

Please sign in to comment.