-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_arrow.html
More file actions
69 lines (42 loc) · 1.35 KB
/
Copy pathfunction_arrow.html
File metadata and controls
69 lines (42 loc) · 1.35 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//Arrow function
const saludar = () => console.log("Hola")
saludar()
//No es necesario poner los () cuando ya hay un parametro
const hello = nombre => console.log(`Hello ${nombre}`);
hello("Christian")
//--------------------------------------------------------------------------
const sumar = function(a,b){
return(a+b);
}
console.log(sumar(5,6));
//Usamos Arrow function para la misma function
//Como hay varios parametros, se de usar parentesis (a,b)
const suma = (a,b) => a+b
console.log(suma(8,9));
//Cuando hay mas de una linea de codigo se debe usar las {}
const funciondevariaslineas = () => {
console.log("uno")
console.log("dos")
console.log("tres")
}
console.log(funciondevariaslineas())
//Metodo ForEach Arrow function
//ForEach normal
const numeros = [1,2,3,4]
numeros.forEach(function(el,index) {
console.log(`el elemento ${el}, esta en la posicion ${index}`)
});
//ForEach Arrow Function
numeros.forEach((el,index) => console.log(`${el}, esta en la posicion ${index}`));
//
</script>
</body>
</html>