// Scoping and Destructuring
function extractData() {
if (true) {
let { name, age } = { name: "John", age: 30 };
console.log(name); // "John"
}
console.log(name); // Error: 'name' is not defined
}
extractData();
// Block Scoping
function blockScopeDemo() {
if (true) {
let message = "Inside if block";
console.log(message); // "Inside if block"
}
console.log(message); // Error: 'message' is not defined
}
blockScopeDemo();
// Hoisting
function hoistingDemo() {
console.log(hoistedVar); // undefined
var hoistedVar = "I am hoisted!";
console.log(hoistedVar); // "I am hoisted!"
}
hoistingDemo();