I'm pretty new to coding and can't find out why this is outputting undefined:
var var0, list = [var0];
list[0] = true;
console.log(var0)
I'm pretty new to coding and can't find out why this is outputting undefined:
var var0, list = [var0];
list[0] = true;
console.log(var0)
On line 1 you copy the value of var0 into the array.
On line 2 you replace the value in the array.
This doesn't have any effect on var0. That is just a variable that used to have a copy of the same value. It is not a reference.
You never use or define the value of var0.
list[0] = true;
This line replaces the value of the object in the 0 position (which is var0 because of the first line) to a boolean variable with the value "true".
What you mean to do is
var var0 = true, list = [var0];
console.log(list[0])