JavaScript Quickie: Shorthand Variable Assignment
JavaScript Quickies are tips/tricks in 3 minutes or less. Today: Shorthand Variable Assignment.

Variables with equal values
// LONG WAY
var a = 1;
var b = 1;
var c = 1;// SHORT WAY
var a = b = c = 1;
Variables with different values
// LONG WAY
var d = 2;
var e = 3;
var f = 4;// SHORT WAY
var d = 2, e = 3, f = 4;
Bonus: Shorthand Assignment Operators
If you’re adding, subtracting, multiplying, dividing, or remaindering two values, there’s no need to type out the entire equation. Use these shorthands to save time and code:
Long way:
var x = 1;
var y = 2;
x = x + y;console.log(x);
// 3
Shorthand:
var x = 1, y = 2;
x += y;console.log(x);
// 3
Other Shorthands:
x = x + y -> x += y
x = x - y -> x -= y
x = x * y -> x *= y
x = x / y -> x /= y
x = x % y -> x %= y
❤ If this post was helpful, please hit the little blue heart! And don’t forget to check out my other recent articles:
- JavaScript: Why does 3 + true = 4? (and 7 other tricky equations)
- And when you’re ready to really dive into Web Development, Check out the 5 Best Courses for Learning Full Stack Web Development