• support@answerspoint.com

Set multiple variables to the same value in Javascript

1973

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

1Answer


0

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 7 years ago
  • Community  wiki

Your Answer

    Facebook Share        
       
  • asked 7 years ago
  • viewed 1973 times
  • active 7 years ago

Best Rated Questions