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
// Toda função em JavaScript retorna alguma coisa, se o return não foi declarado, ela não retornará nada, portanto undefined. | |
// Alguns métodos podem exigir que retorne algum valor. | |
const returnIndefinido = () => { | |
'Olá' | |
} | |
returnIndefinido() // undefined | |
const returnDeclarado = () => { | |
return 'Olá' | |
} |
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
// Testes para o Quiz Chaining Thens | |
const data = { | |
name: 'Daniel', | |
age: 30, | |
studying: [ "JavaScript", "React" ] | |
} | |
const promiseTest = () => { | |
return new Promise(resolve => { |
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 condicao() { | |
return Math.floor(Math.random() * (4-1)) === 1 | |
} | |
function atraso(ms) { | |
return new Promise((resolve, reject) => { | |
setTimeout(function() { | |
condicao() ? resolve('Foi que foi') : reject('Deu ruim') | |
},ms) | |
}) |
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
// Callback | |
const callback = () => { | |
console.log('Depois aqui.') | |
} | |
const primeiro = (cb) => { | |
console.log('Primeiro aqui.') | |
return cb() | |
} | |
primeiro(callback) |
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 Teste { | |
constructor() { | |
this.oi = 'Bom Dia' | |
} | |
// problema com o this | |
bomDiaUndefined() { | |
setTimeout(function() { | |
console.log(this.oi) | |
}, 1000) | |
} |
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
/* | |
não estamos criando literalmente cada método na instanciação do | |
objeto, é uma referência aos prototypes, por isso funciona... | |
*/ | |
function Quadrupede() { | |
this.patas = 4 | |
this.cabeca = 1 | |
} | |
function Snoopy() { |
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
# OS generated files - https://github.com/github/gitignore # | |
############################################################ | |
# General | |
.DS_Store | |
.AppleDouble | |
.LSOverride | |
# Icon must end with two \r | |
# "Icon[\r]" | |
# VIM -> Icon[^M], Icon["CtrlV->Enter"] |
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
// Como as vars | |
let i = 1 | |
for (i = 1; i < 4; ++i) { | |
setTimeout(() => console.log(i), i*1000) | |
} // expect 4 4 4 | |
// Escopo a cada iteração | |
for (let i = 5; i < 8; ++i) { | |
setTimeout(() => console.log(i), i*1000) | |
} // expect 5 6 7 |