Haradzieniec Haradzieniec - 6 months ago 18
Javascript Question

Javascript expression shortage: value? value:'100'

Is there any shorter way to write the expression

value? value:'100'

the way I don't type

Something like (but it is wrong)

value? : '100'
//take value unless it is empty/null/false/undefined/0, otherwise accept '100'.

Or, whatever is possible would be fine.


You can use the logical OR operator:

value || '100'

It'll return value if it's truthy (!!value === true), else '100'.