1+ /*
2+ Clase 4 en vídeo | 31/07/2024
3+ Mapas, bucles y funciones
4+ https://www.twitch.tv/videos/2212289583?t=00h17m45s
5+ */
6+
7+ // Funciones
8+
9+ // Simple
10+
11+ function myFunc ( ) {
12+ console . log ( "¡Hola, función!" )
13+ }
14+
15+ for ( let i = 0 ; i < 5 ; i ++ ) {
16+ myFunc ( )
17+ }
18+
19+ // Con parámetros
20+
21+ function myFuncWithParams ( name ) {
22+ console . log ( `¡Hola, ${ name } !` )
23+ }
24+
25+ myFuncWithParams ( "Brais" )
26+ myFuncWithParams ( "MoureDev" )
27+
28+ // Funciones anónimas
29+
30+ const myFunc2 = function ( name ) {
31+ console . log ( `¡Hola, ${ name } !` )
32+ }
33+
34+ myFunc2 ( "Brais Moure" )
35+
36+ // Arrow functions
37+
38+ const myFunc3 = ( name ) => {
39+ console . log ( `¡Hola, ${ name } !` )
40+ }
41+
42+ const myFunc4 = ( name ) => console . log ( `¡Hola, ${ name } !` )
43+
44+ myFunc3 ( "Brais Moure" )
45+ myFunc4 ( "Brais Moure" )
46+
47+ // Parámetros
48+
49+ function sum ( a , b ) {
50+ console . log ( a + b )
51+ }
52+
53+ sum ( 5 , 10 )
54+ sum ( 5 )
55+ sum ( )
56+
57+ function defaultSum ( a = 0 , b = 0 ) {
58+ console . log ( a + b )
59+ }
60+
61+ // Por defecto
62+
63+ defaultSum ( )
64+ defaultSum ( 5 )
65+ defaultSum ( 5 , 10 )
66+ defaultSum ( b = 5 )
67+
68+ // Retorno de valores
69+
70+ function mult ( a , b ) {
71+ return a * b
72+ }
73+
74+ let result = mult ( 5 , 10 )
75+ console . log ( result )
76+
77+ // Funciones anidadas
78+
79+ function extern ( ) {
80+ console . log ( "Función externa" )
81+ function intern ( ) {
82+ console . log ( "Función interna" )
83+ }
84+ intern ( )
85+ }
86+
87+ extern ( )
88+ // intern() Error: fuera del scope
89+
90+ // Funciones de orden superior
91+
92+ function applyFunc ( func , param ) {
93+ func ( param )
94+ }
95+
96+ applyFunc ( myFunc4 , "función de orden superior" )
97+
98+ // forEach
99+
100+ myArray = [ 1 , 2 , 3 , 4 ]
101+
102+ mySet = new Set ( [ "Brais" , "Moure" , "mouredev" , 37 , true , "[email protected] " ] ) 103+
104+ myMap = new Map ( [
105+ [ "name" , "Brais" ] ,
106+ 107+ [ "age" , 37 ]
108+ ] )
109+
110+ myArray . forEach ( function ( value ) {
111+ console . log ( value )
112+ } )
113+
114+ myArray . forEach ( ( value ) => console . log ( value ) )
115+
116+ mySet . forEach ( ( value ) => console . log ( value ) )
117+
118+ myMap . forEach ( ( value ) => console . log ( value ) )
0 commit comments