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
JavaScript Functions
JavaScript Arrow Functions
Constructor Functions in JavaScript
JavaScript this Keyword
Exercises & Assignments
No Content Found.
Interview Questions & Answers
What are arrow functions in JavaScript?
What is the this keyword in JavaScript?
What is the difference between call, apply and bind?
What is the difference between debounce and throttle?
What is the difference between function declaration and function expression?
What is a closure in JavaScript?