I love those short js oneliners. I’d like to know if there’s something logical and elegant for:
- intializing a variable to zero if undefined
- increment by one otherwise.
Shorter than this preferrably 😉
var obj = {} ;
//some iterative called function
obj.prop = obj.prop===undefined?0:obj.prop++;
This will result in
NaNfor the first increment, which will default to0.