I have a piece of javascript code that uses the ECMA6 dataset property to access an objects data-foo attribute of an element e. Unfortunately, this is not compatable with <=IE10. To combat this, I’ve rewritten my code to using a ternary operator, using dataset when supported and getAttribute when not: But why shouldn’t I just replace the entire line with
Tag: ternary-operator
Ternary shorthand for foo ? foo : bar
I realized I am using the ternary operator most of the time as following: foo ? foo : bar; This becomes cumbersome, as the variable length gets quite long, e. g. appModel.settings.notifications ? appModel.settings.notifications : {}; Is there any shorthand or more elegant way of doing this? Perhaps ES6 or ES7? Answer You can write it like this : you