On this page
- 1 JavaScript: How ES6 Arrow Function Can Help You
- 2 JavaScript: How ES6 Arrow Function Can Help You
- 2.1 Syntax:
- 2.2 Advanced syntax
- 2.2.0.1 Introduction to the DOM
- 2.2.0.2 How to apply CSS to iframe?
- 2.2.0.3 JavaScript Map, Reduce, and Filter
- 2.2.0.4 JavaScript Concepts Everyone Should Learn!
- 2.2.0.5 JavaScript: localStorage and sessionStorage
- 2.2.0.6 JavaScript: Array functions/methods
- 2.2.0.7 JavaScript: Array map() Method
- 2.2.0.8 Promise in JavaScript with example
- 2.2.0.9 JavaScript: FormData
- 2.2.0.10 ES6: Spread syntax
- 2.2.0.11 ES6: Spread operator
- 2.2.0.12 ES6: Introduction
- 2.2.0.13 JavaScript: Scope and the Variable this
- 2.2.0.14 JavaScript: Get Element
- 2.2.0.15 JavaScript: JSON (JavaScript Object Notation)
- 2.2.0.16 JavaScript: Application programming interface (API)
- 2.2.0.17 Javascript : Date & Time Program
- 2.2.0.18 JavaScript: What is AJAX?
- 2.2.0.19 JavaScript: Getting started
- 2.3 One Comment
- 2.4 Leave A Comment Cancel reply
JavaScript: How ES6 Arrow Function Can Help You
JavaScript: How ES6 Arrow Function Can Help You
February 25, 2021
An Arrow function is a compact alternative to a traditional function expression, but is limited and can’t be used in all situations.
Syntax:
//One param. With simple expression return is not needed: param => expression //Multiple params require parentheses. With simple expression return is not needed: (param1, paramN) => expression //Multiline statements require body brackets and return: param => { let a = 1; return a + param; } //Multiple params require parentheses. Multiline statements require body brackets and return: (param1, paramN) => { let a = 1; return a + param1 + paramN; }
Advanced syntax
//To return an object literal expression requires parentheses around expression: params => ({foo: "a"}) // returning the object {foo: "a"} //Rest parameters are supported: (a, b, ...r) => expression //Default parameters are supported: (a=400, b=20, c) => expression //Destructuring within params supported: ([a, b] = [10, 20]) => a + b; // result is 30 ({ a, b } = { a: 10, b: 20 }) => a + b; // result is 30
Your article gave me a lot of inspiration, I hope you can explain your point of view in more detail, because I have some doubts, thank you.