Have you ever tried to validate NaN using == or ===? could you correctly guess the output of below statements? 1. x=parseInt("string") 2. console.log(x) 3. x==NaN 4. x===NaN 5. NaN===NaN 6. isNaN(x) well, if you correctly answerd all the statements then congtars, but if don't; don't worry, i will try to give a walk through. Let's first the output first - x=parseInt("string") NaN console.log(x) NaN x==NaN false x===NaN false NaN===NaN false isNaN(x) true It is not possible to rely on the equality operators (== and ===) to determine whether a value is NaN or not, because both NaN == NaN and NaN === NaN evaluate to false. Hence, the necessity of an isNaN function. source - http://droidscript.org
You are given four integers 'a', 'b', 'y' and 'x', where 'x' can only be either zero or one. Your task is as follows: If 'x' is zero assign value 'a' to the variable 'y', if 'x' is one assign value 'b' to the variable 'y'. You are not allowed to use any conditional operator (including ternary operator). Possible Solutions: 1. y = (1 - x) * a + x * b; 2.y = a ^ ((a ^ b) & (x))