DEV Community

Cover image for JavaScript Map is getting upsert!

JavaScript Map is getting upsert!

Laurie on May 19, 2020

This post originally appeared on laurieontech.dev Let's introduce a new (potential) piece of syntax in JavaScript! What is Map? Map is...
Collapse
 
drmandible profile image
DrMandible

Is this different than assigning new values with spread operator?

Collapse
 
laurieontech profile image
Laurie

The spread operator is not valid inside Map's set function so far as I am aware.

Collapse
 
omenlog profile image
Omar E. Lopez

Thanks for share it, that is a very good addition. One question:

What do you mean by Map doesn't have prototype at all ?

I did a little test on my machine an got this

image

Collapse
 
craigmc08 profile image
Craig McIlwrath

I believe he misspoke. His comparison was that, when using a plain Object as a map, you have to worry about the keys from the prototype chain. When using a Map, there are no keys already defined in the Map. A Map object is still and object and still uses the prototype chain to define itself.

Collapse
 
jenc profile image
Jen Chan

Wait... this is stage 2 so it's not out yet right?

Collapse
 
laurieontech profile image
Laurie

Yup! That’s why I note it as a potential piece of syntax.

Collapse
 
ben profile image
Ben Halpern

This is really great news

Collapse
 
sargalias profile image
Spyros Argalias

Very nice :). Looks quite convenient!

Collapse
 
flexjames profile image
James Ma

So cool, that’s for the post!