This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| a = 5; | |
| b = "hola"; | |
| console.log(a); // 5 | |
| console.log(b); // hola | |
| console.log(a, b); // 5 hola | |
| console.log(b, a); // hola 5 | |
| console.log(a, a); // 5 5 | |
| console.log(b, b); // hola hola |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const a = 7; | |
| a = 8; // reasignación | |
| console.log(a);// TypeError: Assignment to constant variable. | |
| let b = 7; // mismo resultado para var a = 7 | |
| b = 9; | |
| console.log(b); // 9 var y let pueden ser reasignadas |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // function myFuncion() { | |
| // return 3 + 4; | |
| // } | |
| // console.log(myFuncion()); // 7 | |
| function myFuncion(a, b) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // function myFuncion() { | |
| // return 3 + 4; | |
| // } | |
| // console.log(myFuncion()); // 7 | |
| // function myFuncion(a, b) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /////////////1º | |
| // if (3>4) { | |
| // console.log("3 es menor que 4"); | |
| // } | |
| // var edad = 17; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| numeros = [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
| texto = ["perro", "gato", "caballo"] | |
| mix = [1, "casa", "auto", 77 ] | |
| // Sus índices comienzan en 0 y se invocan con el nombre de la variable seguido del número de la posición entre corchetes. | |
| console.log(numeros[1]) // 2 | |
| console.log(texto[0]) // perro | |
| console.log(mix[3]) // 77 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Ejemplo 1: | |
| let i; | |
| for (i = 0; i < 5; i++) { | |
| // Se ejecuta 5 veces, con valores desde paso desde 0 hasta 4. | |
| console.log('Dando ', i, ' vuelta'); | |
| }; | |
| //Ejemplo 2: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var persona = { | |
| nombre: 'Juan', | |
| edad: 28, | |
| genero: 'masculino', | |
| intereses: ['lectura', 'fútbol'], | |
| biografia: function () { | |
| console.log(this.nombre + ' tiene ' + this.edad + ' años. Le gusta la ' + this.intereses[0] + ' y jugar al ' + this.intereses[1] + '.'); | |
| }, | |
| saludo: function() { | |
| console.log('Hola, soy '+ this.nombre + '. '); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Objeto String. Incluye métodos como: | |
| // length Devuelve la longitud de una cadena de texto. | |
| var cadena = "hola"; | |
| var longitud = cadena.length; | |
| console.log(longitud); | |
| // toUpperCase() Devuelve la cadena en mayúscula. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!-- Document.getElementById(”valor del atributo id”) devuelve el | |
| elemento que tiene el atributo ID con el valor especificado. --> | |
| <!-- <html> | |
| <body> | |
| <p id="nombreId">GetElementById</p> | |
| <script> | |
| let elemento = document.getElementById("nombreId") | |
| </script> |