What are arrow functions in JavaScript?

An arrow function is a shorter way to write a function. It uses =>.

const square = n => n * n;
const add = (a, b) => a + b;

console.log(square(4));
console.log(add(2, 3));
console.log([1, 2, 3].map(n => n * 2));

Output:

Tutorials Class - Output Window

16
5
[ 2, 4, 6 ]

An arrow function has no own this, no arguments, and cannot be used with new. See Arrow Functions.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.