SyntaxFix
Write A Post
Hire A Developer
Questions
Other way is using short-circuit:
x = (typeof y !== 'undefined') && y || 1
Although I myself think that ternary is more readable.