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 obj = { | |
getNome(){ | |
return this.nome; | |
} | |
}; | |
//seria o equivalente: | |
var obj = { | |
getNome: function(){ | |
return this.nome; | |
} |
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 a = 1; | |
var b = 2; | |
var obj = {a, b}; | |
console.log(obj); // {a: 1, b: 2} | |
//seria o mesmo que | |
var a = 1; | |
var b = 2; | |
var obj = { | |
a: a, | |
b: 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
var list = [1,2,3]; | |
list.map(item => item + "#"); | |
list.map( (item, indice) => item + "#" + indice); | |
//equivalente: | |
list.map(function(item){ | |
return item + "#"; | |
}); |
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
let fn = (p1) => ({ id: p1, nome: "teste"}); | |
fn(1);//{id:1, nome: "teste"} |
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
//Caso não tenha parâmetro pode-se fazer o seguinte | |
let fn = () => 3; | |
fn(); //3 | |
//Caso tenha apenas um parametro não é necessário colocar parenteses: | |
let fn = p1 => p1; | |
fn(3); //3 |
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
let arrayValores = [5, 50, 25, 100] | |
console.log(Math.max(...arrayValores)); // 100 | |
//equivalente: | |
Math.max(5, 50, 25, 100); | |
//ou | |
Math.max.apply(Math, arrayValores); |
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 teste(a, ...b){ | |
console.log(a); | |
console.log(b); | |
} | |
teste("oi", "la" , "se", "ls"); | |
//oi, ["la", "se", "ls"] |
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 teste(a, b=1, c="oi"){ | |
console.log(b); | |
console.log(c); | |
} | |
teste(9); // 1,2 | |
teste("k" ,false, "B"); //false,B | |
teste("a", undefined, 9); // 1,9 //undefined é considerado que o parametro não foi informado | |
//podemos usar expressoes como valores padroes |
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 tagTeste(arrayString, ...arraySubstituicoes) { | |
console.log(arrayString);// ["oi "," tudo bem?"] //também possui a propriedade .raw que é a string crua | |
console.log(arraySubstituicoes);//["teste"] | |
return "olá"; | |
} | |
var a = "teste"; | |
var b = tagTeste`oi ${a} tudo bem?`; | |
console.log(b); //olá |
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 variavel = "oi teste" | |
var teste = ` | |
texto ${variavel} | |
texto | |
texto | |
`; | |
var teste2 = `texto ${teste} fim`; | |
console.log(teste2); |