I have initialized several variables in the global scope in a JavaScript file:
var moveUp, moveDown, moveLeft, moveRight;
var mouseDown, touchDown;
>
The original variables you listed can be declared and assigned to the same value in a short line of code using destructuring assignment. The keywords let
, const
, and var
can all be used for this type of assignment.
let [moveUp, moveDown, moveLeft, moveRight, mouseDown, touchDown] = Array(6).fill(false);