I happened to know the following code
Here is the code, and very simple:
var test = 0 || -1 ;
console.log(test);
then the output in the console is -1
and somehow i am really new into the javascript,
all i think of is that the 0 stands for Boolean False in JS ,and so || operator seems to ignore the 0 and assign the value -1 to the variable
so am i right ?
i just want a confirm
||—expr1 || expr2(Logical OR)&&—expr1 && expr2(Logical AND)All values in Javascript are either “truthy” or “falsy”.
The following values are equivalent to false in conditional statements:
""(\'')All other values are equivalent to true.
So…
var test = 0 || -1 ;returns-1.If it was
var test = 0 || false || undefined || "" || 2 || -1it would return2Logical operator on MDN