A variable declaration and assignment is possible to do within a line, but it seems not possible to do with an array, why?
var variable1 = 5; // Works
var array1[0] = 5; // Doesn't work
var array2 = []; // Works
array2[0] = 5;
An array initialiser has the form:
var a = [5];
When you do:
var array1[0]
then the interpretter sees var and expects it to be followed by an identifier. However, array1[0] is not a valid identifier due to the "[" and "]" characters. If they were, you'd have a variable named array1[0] that has the value 5.
array1[0], it is trying to set the zeroth element ofarray1, which does not existvar array1 = [];