Welcome to my homepage

Best Viewed Without Eyes

Setting multiple variables with a ternary in JS

There's no way this hasn't been documented somewhere already, but it just dawned on me last week, and I thought it was pretty neat!

With the fun power of destructing arrays in #javascript, you can set multiple variables in one go using a ternary expression. Check it.

const [var1, var2, var3] = someVar
  ? ['true value 1', 'true value 2', 'true value 3']
  : ['false value 1', 'false value 2', 'false value 3'];

Not too bad, eh?