Arrow functions are a shorter way to write functions in JavaScript, introduced in ES6 (2015).
They have a cleaner syntax and also handle the this
keyword differently compared to regular functions.
✅ Basic Syntax
Regular function:
function add(a, b) { return a + b; }
Arrow function:
const add = (a, b) => { return a + b; };
If the function body is a single expression, you can omit the curly braces {}
and the return
keyword:
const greet = () => console.log("Hello!"); greet(); // Output: Hello!