-
Notifications
You must be signed in to change notification settings - Fork 3
/
27.4 Arrow Functions in JS.html
42 lines (38 loc) · 1.81 KB
/
27.4 Arrow Functions in JS.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<!DOCTYPE html>
<html lang="en">
<head><title>Arrow functions in JS</title>
</head>
<body>
<!-- visit: https://www.w3schools.com/js/js_arrow_function.asp
Important : All the scope rules that applied on functions are same with Arrow Functions as well
->Arrow function is one of the features introduced in the ES6 version of JavaScript.
It allows you to create functions in a cleaner way compared to regular functions.
For example:
function expression
let x = function(x, y) {
return x * y;
}
can be written as:
using arrow functions
let x = (x, y) => x * y;
using an arrow function.
->The syntax of the arrow function is:
let myFunction = (arg1, arg2, ...argN) => {
statement(s)
}
Here,
- myFunction is the name of the function
- arg1, arg2, ...argN are the function arguments
- statement(s) is the function body
- If the body has single statement or expression, you can write arrow function as:
let myFunction = (arg1, arg2, ...argN) => expression
->Uses of Arrow functions:
Arrow functions introduce concise body syntax, or implicit return. This allows the omission
of the curly brackets and the return keyword. Implicit return is useful for creating
succinct one-line operations in map , filter , and other common array methods.
-->
<script>
//see program 27.5
</script>
</body>
</html>