I have jslint complaining me to use ||
operator for below code,
query = ['browser' + (ieVersion ? ieVersion : 'UNKNOWN')]
I tried using ||
operator but that ends up in wrong result,
query = ['browser' + ieVersion || 'UNKNOWN']
// => ['browserundefined']
Operator precedence is wrong, try this:
query = ['browser' + (ieVersion || 'UNKNOWN')]
without extra parentheses +
operator is stronger and JavaScript engine evaluates it as:
query = [('browser' + ieVersion) || 'UNKNOWN']
Notice that 'browser' + ieVersion
is never falsy so you'll never see 'UNKNOWN'
.
brackets?
query = ['browser' + (ieVersion || 'UNKNOWN')]
You need to wrap the expression in parentheses:
query = ['browser' + (ieVersion || 'UNKNOWN')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With