I have notice a weird behaviour when using the OR logic or the nullish coalescing together with the includes method in a ternary fashion.
const result = 'Hello' || ['e', 'z'].includes('e') ? 'in-array' : 'not-in-array';
console.log(result) // 'in-array'
const result = 'Hello' ?? ['e', 'z'].includes('z') ? 'in-array' : 'not-in-array';
console.log(result) // 'in-array'
const result = 'Hello' || ['e', 'z'].includes('xx') ? 'in-array' : 'not-in-array';
console.log(result) // 'in-array'
const result = 'Hello' ?? ['e', 'z'].includes('xx') ? 'in-array' : 'not-in-array';
console.log(result) // 'in-array'
To make it work, you will have to add parentheses/round brackets to the right end condition.
const result = 'Hello' || (['e', 'z'].includes('e') ? 'in-array' : 'not-in-array');
console.log(result) // 'Hello'
const result = 'Hello' ?? (['e', 'z'].includes('z') ? 'in-array' : 'not-in-array');
console.log(result) // 'Hello'
Is this an expected behaviour? Why is this happening?