0
Javascript simple problem..
z= 'banana' && 'apple'; console.log(z); Why the answer is apple?
2 ответов
+ 3
z= 'banana' && 'apple';
console.log(z); //apple
z = 'apple' && 'banana';
console.log(z) //banana
z = 1 && 2
console.log(z) //2
z = 2 && 1
console.log(z) //1
conclusion - always returns RHS value
Explanation:
as 'banana' is true and 'apple' is true so Right side value will be print
1 is true and 2 is true so answer is 2
if there is 0 && 'apple' then result would be 0
or false && 'apple' => false
true && 'apple' => apple
+ 2
&& "and" will take the last true value as it gets override the others :
let c = "nanana" && "mamama" && 2; //2
As oposite from || "or" , that gets the first true value:
let c = "nanana" && "mamama" && 2; //nanana