0

Javascript simple problem..

z= 'banana' && 'apple'; console.log(z); Why the answer is apple?

25th Jun 2022, 1:03 PM
Sachin
Sachin - avatar
2 odpowiedzi
+ 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
25th Jun 2022, 1:15 PM
A͢J
A͢J - avatar
+ 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
25th Jun 2022, 3:34 PM
Frank Yohan Rodríguez Pérez
Frank Yohan Rodríguez Pérez - avatar