Set multiple variables to the same value in Javascript
I have initialized multiple variables in the global scope in a Javascript file:
var moveUp, moveDown, moveLeft, moveRight;
var mouseDown, touchDown;
I want to set all of these variables to false, this is the code I currently have:
moveUp = false;
moveDown = false;
moveLeft = false;
moveRight = false
mouseDown = false;
touchDown = false;
Is there any way that I can set all of these variables to the same value in one line of code, or is the code I currently have the best way to do this
Javascript
- asked 6 years ago
- G John
1Answer
You are right Nothing stops you from doing
moveUp = moveDown = moveLeft = moveRight = mouseDown = touchDown = false;
Check this example to set multiple variables to the same value in Javascript
var num1, num2, num3;
num1 = num2 = num3 = 20;
console.log(num1 + num2 + num3)
- answered 6 years ago
- Community wiki
Your Answer