Curriculum
Course: JavaScript Basic
Login

Curriculum

JavaScript Basic

JSHome

0/216
Text lesson

Arrow Functions

 Arrow functions provide a concise syntax for writing function expressions.

You no longer need the function keyword, the return keyword, or curly brackets for single-expression functions.

Example

// ES5
var x = function(x, y) {
   return x * y;
}

// ES6
const x = (x, y) => x * y;

Arrow functions lack their own this, aren’t hoisted, and work best when declared with const. While braces and return can be skipped for single statements, including them adds clarity.

Example

const x = (x, y) => { return x * y };