Unlike other multiple assignments in one line questions, this one is different in that:
- It's for assignments/updates
- It's about assignments/updates to hash attributes as well.
Take a look at the following code:
$ cat test.js
let a = b = "-"
console.log(a, b)
[a, b ] = ['abc', 'def']
const h = {a:"1", b:"2"}
console.log(h, h.a)
[h.a, h.b ] = ['abc', 'def']
console.log(h.a)
Everything works fine if running under node
interactively:
> a = b = "-"
'-'
> console.log(a, b)
- -
> [a, b ] = ['abc', 'def']
[ 'abc', 'def' ]
> console.log(a, b)
abc def
> h = {a:"1", b:"2"}
{ a: '1', b: '2' }
> h
{ a: '1', b: '2' }
> [h.a, h.b ] = ['abc', 'def']
[ 'abc', 'def' ]
> h.a
'abc'
However, if running by node
as script, or checking with eslint
, there will be all kinds of problems.
Why running then under node
interactively is OK but not if as a script?
Is it possible to fix it and make it working as script as well?
$ node -v
v16.18.1