The pit of map in Node.js

const deviceLogMap = new Map([
  [0,""],[1,""][3,"2"]]);

in the map above

[1,""][3,"2"]
The number is missing between

, but there is no error message at run time, and the relevant error message cannot be captured.
ask for answers

Mar.04,2021

this is all discovered by you, the bug of V8.
new Map (wrong_iterable) swallow TypeError in file scripts
https://chromium-review.googl.

< H1 > Supplementary instructions < / H1 >

this bug on Map new Map ([iterable]) , but non-iterating parameters do not throw an error to the debugger, you will find that subsequent code cannot be executed, depending on the V8 used by the nodejs version.


think of [3Jing 'Test 2'] as an array index without a comma.

let a = [1,''];
const deviceLogMap = new Map([
  [0,''],a[3,'2']]);

-Update
= = tested that mine reported an error.


clipboard.png

dare to ask what version of your nodejs is.


this does not count as bug. The syntax of
[1pm 'fortification'] [3pi 'test 2'] is true in itself.
is equivalent to

    const arr = [1,'']
    console.log(arr['2'])
//    => undefined

No problem:)

=
tested that my node also reported an error emmm.

Menu