Master function declarations, expressions, and the modern arrow function syntax.
1// Declaration — hoisted, can call before definition2function greet(name) {3 return `Hello, ${name}!`;4}5 6// Expression — NOT hoisted7const add = function(a, b) {8 return a + b;9};10 11console.log(greet("Alice")); // Hello, Alice!12console.log(add(2, 3)); // 5Hello, Alice! 5
1// Standard arrow function2const multiply = (a, b) => {3 return a * b;4};5 6// Concise body (implicit return)7const square = (n) => n * n;8const double = n => n * 2; // Single param: no parens needed9 10console.log(multiply(3, 4)); // 1211console.log(square(5)); // 2512console.log(double(7)); // 1413 14// Arrow in array methods15const nums = [1, 2, 3, 4, 5];16const evens = nums.filter(n => n % 2 === 0);17console.log(evens); // [2, 4]12 25 14 [2, 4]