A
A
Alex Ozerov2020-05-08 13:49:40
JavaScript
Alex Ozerov, 2020-05-08 13:49:40

Why does a Map object return different results with different notations?

There is this code:

let sq = new Map();

sq.set('name', 'value')
  .set('name2', 'value2')

  console.log(`
    ${sq}
  `)

And it returns : But if rewritten to console.log(sq) it will return already Map: I would like to understand, because I like to use back quotes, and I often use them. [object Map]

Map(2) {"name" => "value", "name2" => "value2"}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
hzzzzl, 2020-05-08
@ozerovlife

` ${variable} ` = variable.toString()
it's just that the Map object turns into this when its toString(),
like simple objects, compare

({a: 42}).toString()  // "[object Object]"
console.log({a: 42})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question