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
//ES6 | |
let nombre1 = "JavaScript"; | |
let nombre2 = "awesome"; | |
console.log(`Sólo quiero decir que ${nombre1} is ${nombre2`); | |
// Solo quiero decir que JavaScript is awesome | |
// También podemos tener String multilínea sin necesidad de concatenarlos con +. | |
//ES5 | |
var saludo = "ola " + |
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
function get(URL){ | |
//New Promise recibe una funcion | |
return new Promise((resolve, reject) => { | |
const xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function () { | |
const DONE = 4 | |
const OK = 200 | |
if (this.readyState === DONE) { | |
if(this.status === OK){ |
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
function get(URL, callback){ | |
const xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function () { | |
const DONE = 4 | |
const OK = 200 | |
if (this.readyState === DONE) { | |
if(this.status === OK){ | |
//Todo OK | |
callback(null, JSON.parse(this.responseText)) |
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 sacha = { | |
nombre: 'Sacha', | |
apellido: 'Lifszyc' | |
} | |
function saludar(veces, uppercase) { | |
let str = `Hola ${this.nombre} ${this.apellido}` | |
str = uppercase ? str.toUpperCase() : str | |
for (let i = 0; i < veces; i++) { | |
console.log(str) |
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
class Toggable { | |
constructor(el) { | |
// inicializar el estado interno | |
this.el = el | |
this.el.innerHTML = 'Off' | |
this.activated = false | |
this.onClick = this.onClick.bind(this) // Si no se hace el bind toma como referencia el this el elemento del button | |
this.el.addEventListener('click', this.onClick) | |
} |
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
class Persona { | |
constructor(nombre, amigos = []) { | |
this.nombre = nombre | |
this.amigos = amigos | |
} | |
listarAmigos() { | |
const _this = this | |
this.amigos.forEach((amigo) => { |
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
function saludarFamilia(apellido) { | |
return function saludarMiembroDeFamilia(nombre) { | |
console.log(`Hola ${nombre} ${apellido}`) | |
} | |
} | |
const saludarGomez = saludarFamilia("Gomez") | |
const saludarPerez = saludarFamilia("Perez") | |
const saludarRomero = saludarFamilia("Romero") |
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
function suma(...numeros) { // Los tres puntos significa que vamos a pasar n cantidad de parametros | |
return numeros.reduce(function (acum, numero) { | |
acum += numero | |
return acum | |
}, 0) | |
} | |
// Ahora queremos ejecutar una operación sobre todos los elementos del array, para esto tenemos un método llamado map | |
const dobles = (...numeros) => numeros.map(numero => numero * 2) |
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 nombre = "Sacha" | |
function saludar10() { | |
var nombre | |
if (true) { | |
nombre = "Eric" | |
} | |
console.log(`Hola ${nombre}`) | |
} |
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 p1 = { | |
x: 0, | |
y: 4, | |
moverEnX(x) { | |
this.x += x | |
}, | |
moverEnY(y) { | |
this.y += y | |
} | |
} |