Functions
Arrow Functions
Arrow functions are a shorter way to write functions, and they are everywhere in modern JavaScript.
// regular function
function square(n) {
return n * n;
}
// arrow function
const squareArrow = (n) => n * n;
// several lines need braces and return
const describe = (name, age) => {
const status = age >= 18 ? "adult" : "minor";
return `${name} is an ${status}`;
};
console.log(squareArrow(4), describe("Ali", 21));Output
16 Ali is an adult