Reputation: 505
What is a JS shorthand for the following:
if (typeof bfMax !== 'undefined') {
options.max = bfMax;
}
Upvotes: 2
Views: 548
Reputation: 179046
The concise, readable, maintainable, shorthand for assigning a value conditionally is:
if (typeof bfMax !== 'undefined') {
options.max = bfMax;
}
and it appears that you're already using it.
If you want to minify the script to make it shorter, less readable, and unmaintainable, you can use:
typeof bfMax!=='undefined'&&(options.max=bfMax)
Of course, you'll want to swap out your variable names to make things shorter:
typeof b!=='undefined'&&(o.max=b)
Upvotes: 4