Setting a default variable value in a function
There's really no shorter clean way than
var int = arg || 400;
In fact, the correct way would be longer, if you want to allow arg to be passed as 0
, false
or ""
:
var int = arg===undefined ? 400 : arg;
A slight and frequent improvement is to not declare a new variable but use the original one:
if (arg===undefined) arg=400;