1

Currently I'm using:

input = input ? input : 'splash';

which I know is too verbose.

What is the shorter way to do this?

2 Answers2

0

You can use the 'logical OR assignment' and make it even shorter:

input = input || 'splash';

If the input is Truthy value then its will take it, otherwise its will take 'splash'.

Jumpa
  • 878
  • 1
  • 8
  • 12
0

You could try this using the or operator:

var input = 'input';
var input2 = false;

var splash = 'splash'

input || splash // logs input
input2 || splash // logs splash

Jsbin example

Stackoverflow explanation

Community
  • 1
  • 1
omarjmh
  • 13,632
  • 6
  • 34
  • 42