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.
window.addEventListener('keydown', KD); var left, up, right, down, list = [left, up, right, down]; function KD(event) { let LA = 0; for (a = 37; a !== 41; a++) { if (event.keyCode == a) { list[LA] = true; } LA++ } LA = 0; } I guess I'll have to go back to using a bunch of if statements...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])
var0. What do you expect it to be?list[0]is the first item of the list. You don't have pointers and references here, just values -[var0]just creates an array[undefined], nothing more. There is no relation with the variable after the creation oflist.