Does anyone know if using the || operator to group values while comparing a single variable is valid in the most recent versions of JavaScript or TypeScript? If not, what could be preventing this from becoming a valid syntactic sugar feature at some point? And if it is allowed, in which version of JS was this functionality added and what is the name of this type of shortcut comparison?
const exampleVar: 'a' | 'b' | 'c' | 'd' = 'a'
// Checking if exampleVar is 'a' or 'b'
if ( exampleVar === ('a' || 'b') ) {
console.log('Yay!');
} else {
console.log("Not 'a' or 'b' - Boo!");
}
I would expect this to return true if exampleVar is 'a' or 'b'. It seems to work in console in modern browsers, so my main questions are where can this be safely used and what is this technique called so I can verify its support on platforms like CanIUse.