Contents

About ES6 syntax 2 (Arrow Function)

   Aug 8, 2023     1 min read

This article introduced ES6 Syntax (Arrow Function)

This post is to summarize ES6 syntax, which I recently revisited in preparation for a coding test.

ES6 stands for ECMAScript, a standardized version of JavaScript released in 2015.

You can learn more about ES6 here: #### What is an Arrow Function?

Arrow functions have some limitations and can’t be used in every situation. A function expression can also be expressed as an arrow function. The addition of arrow functions allows you to represent functions concisely, making them more readable and maintainable. If the body of the function contains only a return, the arrow function can omit the return and {}. However, the return and {} must be omitted together. In the return statement, you can use the parentheses.

Arrow Function Example
const materials = ["Hydrogen", "Helium", "Lithium", "Beryllium"];

console.log(materials.map((material) => material.length));
// Expected output: Array [8, 6, 7, 9]

As shown in the example, the arrow function allows us to write more concise code.