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 setDados = new Set() | |
let funcao = function() {} | |
let obj = {} | |
setDados.add(1) | |
setDados.add(1) | |
setDados.add(2) | |
setDados.add(3) | |
setDados.add(3) | |
setDados.add(4) |
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 mapa = new WeakMap() | |
mapa.set(1, "Eu sou o número 1") | |
console.log(mapa.get(1)) |
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
carro = null | |
console.log(mapa.get(carro)) // undefined |
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 mapa = new WeakMap() | |
let pessoa = {} | |
let carro = {} | |
mapa.set(pessoa, "Eu sou uma pessoa") | |
mapa.set(carro, "Eu sou um carro") | |
console.log(mapa.get(pessoa)) // Eu sou uma pessoa | |
console.log(mapa.get(carro)) // Eu sou um carro |
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
mapa.clear() | |
console.log(mapa.size) // 0 |
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
for(let elemento of mapa.entries()){ | |
console.log(elemento) | |
} |
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
for(let valor of mapa.values()){ | |
console.log(valor) | |
} |
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
for(let chave of mapa.keys()){ | |
console.log(chave) | |
} |
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
mapa.delete(2) | |
console.log(mapa.has(2)) // 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
console.log(mapa.has("texto")) // true | |
console.log(mapa.has(2)) // true | |
console.log(mapa.has("Olá, mundo!")) // false | |
console.log(mapa.has(5)) // false |