Functions let you write reusable blocks of code. Understanding function scope, closure, and the difference between function and block scope is key to writing modular, bug-free JavaScript.
function add(a, b) {
return a + b;
}
const multiply = (x, y) => x * y;function add(a, b) {
return a + b;
}
console.log(add(3, 5)); // 8
const multiply = (x, y) => x * y;
console.log(multiply(4, 5)); // 20Create an add function and an arrow function multiply, then log their results.
Functions let you write reusable blocks of code. Understanding function scope, closure, and the difference between function and block scope is key to writing modular, bug-free JavaScript.
function add(a, b) {
return a + b;
}
const multiply = (x, y) => x * y;function add(a, b) {
return a + b;
}
console.log(add(3, 5)); // 8
const multiply = (x, y) => x * y;
console.log(multiply(4, 5)); // 20Create an add function and an arrow function multiply, then log their results.