Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

333
Visualizações
Is there any advantage to using Object.create(null) over a Map?

I've seen people use code that looks like

const STUFF_MAP = Object.create(null);

STUFF_MAP would like suggested only be used like a map, so I understand why using Object.create(null) is better than {} (removing the properties that could cause conflicts etc.), but is there any advantage to not just use

const STUFF_MAP = new Map();

When would I use each one? Does it have to do with being compiled to pre es6?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Does it have to do with being compiled to pre es6?

Yes, Object.create(null) is ES5 and won't need a polyfill for Map, if you need to support old browsers.

Apart from that, you should prefer the more modern Map which is also clearly indicates the purpose of a variable. You will need to access the collection using has/get/set methods, not in operator/bracket syntax/assignment. This can sometimes lead to code that isn't as concise, e.g. for incrementing a value you cannot use a compound assignment operator.

As for performance, there should not be much of a difference; if you care, do a benchmark for your particular situation.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda