forked from mouredev/hello-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16-functions.js
More file actions
101 lines (73 loc) · 1.57 KB
/
16-functions.js
File metadata and controls
101 lines (73 loc) · 1.57 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//Funciones
function myFunc(){
console.log("hola mi funcion!")
}
for (let i=0;i<5;i++){
myFunc()
}
//Con parametros
function myFuncionConParametros(name){
console.log(`¡hola, ${name}!`)
}
myFuncionConParametros("oliver")
myFuncionConParametros("rustrian")
//Funciones anónimas
const myfunction2 = function (name){
console.log(`¡hola, ${name}!`)
}
myfunction2("Oliver Rustrian")
//Arrow functions
const myFunc3= (name)=>{
console.log(`¡hola, ${name}!`)
}
myFunc3("Leaho Burgos")
const myFunc4= (name)=>
console.log(`¡hola, ${name}!`)
myFunc4("Oliver Burgos")
//parametros
function sum(a,b)
{
console.log(a+b)
}
sum(2,6)
function defaultSum(a=0,b=0)
{
console.log(a+b)
}
defaultSum()
defaultSum(5)
defaultSum(4,3)
//Retorno de valores
function multi(a,b){
return a*b
}
let result=multi(5,10)
console.log(result)
//Funciones anidadas
function extern(){
console.log("funcion externa")
function inter(){
console.log("funcion interna")
}
inter()
}
extern() //intern fuera del scope
//Funciones de orden superior
function applyFunc(func,param){
func(param)
}
applyFunc(myFunc4,"Funcion de orden superior")
//forEach
myArray=[1,2,3,4]
myset = new Set (["Oliver","Rustrian","olirustrian",20,true,"algo"])
myMap= new Map([
["Name","Oliver"],
["Apellido","Rustrian"],
])
myArray.forEach(function (value){
console.log(value)
})
myArray.forEach((value)=>console.log(value))
myset.forEach((value)=> console.log(value))
myMap.forEach((value)=>console.log(value))