closure:
A closure in JavaScript is a feature where an inner function retains access to the variables of its outer (enclosing) function, even after the outer function has finished executing.
example:
<script>
function bank(){
let min_balance = 500;
const actions = {
deposit : function (amt){
min_balance = min_balance + amt;
},
withdraw : function (amt){
min_balance = min_balance - amt
},
checkbalance : function(){
console.log(min_balance)
}
}
return actions;
}
const customer1 = bank();
customer1.deposit(500);
customer1.checkbalance();
</script>
output:
1000
Localstorage:
- JavaScript localStorage is a feature that lets you store data in your browser using key-value pairs.
- The data stays saved even after you close the browser, so it can be used again when you open it later.
- This helps keep track of things like user preferences or state across different sessions.
Syntax:
localStorage
Save Data to Local Storage:
localStorage.setItem(key, value);
Read Data from Local Storage:
let lastname = localStorage.getItem(key);
Remove Data from Local Storage:
localStorage.removeItem(key);
Remove All (Clear Local Storage):
localStorage.clear();
Top comments (0)