Created
December 16, 2016 05:43
-
-
Save anonymous/42491ae2a55a67667211380d0f926a5e to your computer and use it in GitHub Desktop.
This file contains 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 miValor = 5; | |
miValor = 6; // <--- Error, la constante ya fue asignada. |
This file contains 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 miObjeto = {}; | |
miObjeto.miValor1 = "miValorA"; // <-- Válido, estamos modificando un objeto mutable. | |
miObjeto.miValor1 = "miValorB"; // <-- Válido, estamos modificando un objeto mutable. | |
miObjeto = {miValor1: "miValorC"}; // <--- Error, la asignación a una constante. |
This file contains 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
if(true){ | |
let variable = "algun valor"; | |
} | |
console.log(variable); // <-- Error dado que variable no está declarado en este alcance |
This file contains 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
let guardarValor, obtenerValor; | |
{ // <-- Declaración de un bloque de código libre. | |
let datos = {}; // <-- Variable let declarada dentro del bloque libre. | |
guardarValor = function(llave, valor){ // <-- Asignación de valores a las variables declaradas por fuera. | |
datos[llave] = valor; | |
}; | |
obtenerValor = function(llave){ // <-- Asignación de valores a las variables declaradas por fuera. | |
return datos[llave]; | |
} | |
} | |
guardarValor("12", "Anna"); | |
guardarValor("13", "Diego"); | |
console.log(obtenerValor("12")); // <-- Anna | |
console.log(datos); // <-- Error dado que datos que no está declarado en este bloque de código. |
This file contains 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 guardarValor, obtenerValor; | |
(function(){ // <-- Declaración de un bloque de código libre. | |
var datos = {}; // <-- Variable let declarada dentro del bloque libre. | |
guardarValor = function(llave, valor){ // <-- Asignación de valores a las variables declaradas por fuera. | |
datos[llave] = valor; | |
}; | |
obtenerValor = function(llave){ // <-- Asignación de valores a las variables declaradas por fuera. | |
return datos[llave]; | |
} | |
}()); | |
guardarValor("12", "Anna"); | |
guardarValor("13", "Diego"); | |
console.log(obtenerValor("12")); // <-- Anna | |
console.log(datos); // <-- Error dado que datos que no está declarado en este bloque de código. |
This file contains 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
if(true){ | |
// ----------- inicio del alcance de miVariable | |
llamarAlgunaFuncion(); | |
// ------------ Más código.... | |
let miVariable = "miValor"; | |
// ------------ Más código.... | |
llamarAlgunaOtraFuncion(); | |
// ------------ Fin del alcance de miVariable | |
} |
This file contains 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
{ | |
console.log(miVariable); // <-- Lanza un error de referencia dado que miVariable aún no está definida. | |
let miVariable = "miValor"; | |
} |
This file contains 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 myVal = "$Cadena de texto"; | |
console.log(myVal.endsWith('o')); // true | |
console.log(myVal.endsWith('t')); // false |
This file contains 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 myVal = "$Cadena de texto"; | |
console.log(myVal.includes('dena')); // true | |
console.log(myVal.includes('f')); // false |
This file contains 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 myVal = "adb"; | |
console.log(myVal.padEnd(10, "$")); // <-- adb$$$$$$$ |
This file contains 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 myVal = "adb"; | |
console.log(myVal.padStart(10, "$")); // <-- $$$$$$$adb |
This file contains 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 myVal = "$Cadena de texto"; | |
console.log(myVal.repeat(3)); // "$Cadena de texto$Cadena de texto$Cadena de texto" |
This file contains 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 myVal = "$Cadena de texto"; | |
console.log(myVal.startsWith('$')); // true | |
console.log(myVal.startsWith('C')); // false |
This file contains 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 myVal1 = "A"; | |
const myVal2 = 2; | |
const template = `I just run from ${myVal1} at ${myVal2} ms/s`; | |
console.log(template); // `I just run from A at 2 ms/s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment