# Javascript - Arrow Function Expression

An arrow function expression has a shorter syntax than a function expression and does not bind its own:

• this,
• arguments,
• super,
• or new.target.

These function expressions are best suited for non-method functions.

As an arrow function does not:

• bind its own this, it doesn't create then its own this context, this has its original meaning from the enclosing context (even in non strict).
• bind an arguments object. Arguments are simply a reference to the same name in the enclosing scope.
• bind to new.target. It cannot be used as constructors and will throw an error when used with new.

## Syntax

### Javascript

``````(param1 = defaultValue1, param2, …, paramN = defaultValueN) => { statements }
(param1 = defaultValue1, param2, …, paramN = defaultValueN) => expression  // equivalent to { return expression; }```
```

where:

• parentheses are optional with one parameter
• parentheses are mandatory without parameter and for several parameters
• defaultValue1…N are default parameter

The following syntax is also supported:

### Typescript

``````const myFunction = (param1: Type1, param2: Type2): ReturnType => {
// function body
}```
```

## Example

### Circle Area

``````var area = (r) => Math.PI * r ** 2;
var rayon = 3;
console.log(`The area of a circle with the rayon \${rayon} is \${area(rayon)}`);```
```

### Destructuring Assignment

````var f = ([a, b] = [1, 2], {x: c} = {x: a + b}) => a + b + c;`
```

where:

• in [a, b] = [1, 2]:
• a get the value 1
• b get the value 2
• in {x: c} = {x: a + b}
• c get the value a + b thus 3
• then a + b + c equal:
````console.log(f());  // 6`
```

## Documentation / Reference

Recommended Pages
CommonJs (NodeJs) - Require

The import functionality implementation of commonjs (and then node) is done via the require function require basically: reads a Javascript file (generally a CommonJs module but it may be any javascript...
ES - ES6 Harmony (ES2015)

ECMAScript 6 (also known as ES2015). The first ECMAScript Harmony specification, it is also known as ES6 Harmony class declarations (class Foo... Functional Programming - Map

A page the map functional programming function The map method creates a new collection with the results of calling a provided function on every element in the collection. The map operation produces... Javascript - Functions

Functions functionalities in Javascript. A function in Javascript is a variable that’s given a reference to the function being declared. The function itself is a value (as an integer or an array) that...
Javascript - Map function (Functional programming)

The functional programming function map in a Javascript context is only an array method as all functional programming javascript method. map With an Arrow function as argument Letters that we...
{"ft_lang_label":"__label__en","ft_lang_prob":0.5393297,"math_prob":0.9168888,"size":1400,"snap":"2023-14-2023-23","text_gpt3_token_len":382,"char_repetition_ratio":0.12750717,"word_repetition_ratio":0.0546875,"special_character_ratio":0.3092857,"punctuation_ratio":0.17557251,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9532931,"pos_list":[0,1,2,3,4,5,6],"im_url_duplicate_count":[null,5,null,2,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2023-06-06T16:06:23Z\",\"WARC-Record-ID\":\"<urn:uuid:c279d65b-cf58-403f-85ac-5750fba06e80>\",\"Content-Length\":\"194683\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:6d1faad8-b31b-4e46-b236-220f477f112c>\",\"WARC-Concurrent-To\":\"<urn:uuid:ae10e9e6-21f3-408f-9996-91695fa8233c>\",\"WARC-IP-Address\":\"104.21.30.14\",\"WARC-Target-URI\":\"https://datacadamia.com/web/javascript/es/arrow\",\"WARC-Payload-Digest\":\"sha1:WYVUHB6Q5YAIHCEK2O7Z4ZFX4NM3XW6O\",\"WARC-Block-Digest\":\"sha1:APJNMJ6AWLP2XBCXSRMPNDQ7R3CHZW2M\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2023/CC-MAIN-2023-23/CC-MAIN-2023-23_segments_1685224652959.43_warc_CC-MAIN-20230606150510-20230606180510-00771.warc.gz\"}"}