Arrow Functions are a shorter syntax for writing function expressions in JavaScript. They were introduced in ES6 and are especially useful for writing concise code.
// Traditional function
function add(a, b) {
return a + b;
}
// Arrow function
const addArrow = (a, b) => a + b;
console.log(addArrow(3, 4)); // 7
If the function body has a single expression, you can omit the return
and curly braces:
const square = x => x * x;
console.log(square(5)); // 25
Arrow functions do not have their own this
. They inherit it from the parent scope, making them great for callbacks.
this
arguments
objectnew
)Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!