I am interested in creating an array with just one value inside it on the spot without having to use a variable. The following code achieves that using a variable:
var arr = [];
arr.push('test');
console.log(arr); // correctly logs ["test"]
However, this approach does not work:
console.log([].push('test')); // logs 1
Why does this output 1
instead of ["test"]
? Is it coerced into a boolean?