I tried this in the chrome dev tools console:
let a = [[null,null],[null,null]]
function na(){ return Array(2).fill(Array(2)) }
let b = na();
console.log(JSON.stringify(a))
// [[null,null],[null,null]]
console.log(JSON.stringify(b))
// [[null,null],[null,null]]
So far, so good. I was expecting both a and b with the same values and strucuture. Then I wanted to test a small function that should append an extra value in each line:
function add(x) { x.map( line => line.push(null) )}
add(a)
console.log(JSON.stringify(a))
// [[null,null,null],[null,null,null]]
add(b)
console.log(JSON.stringify(b))
// [[null,null,null,null],[null,null,null,null]]
// ?! I was not expecting this extra value here...
Well, that was unexpected.
Why is that extra null appearing in add(b)
?