+ 3
What is the output of this code???
alert("john" || "user"); // Answer is john.. alert("john" && "user"); //Answer is user Does anyone know how the answer came about?
13 Respuestas
+ 11
|| and && in JS don't return true or false like other lenguages, but the first value that halts the short-circuit evaluation
That means that || returns the first true value or the last false one
while && returns the first false value or the last true one
+ 7
Read the following, they helped me understand it.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND
+ 3
https://en.m.wikipedia.org/wiki/Truth_value
https://en.m.wikipedia.org/wiki/Short-circuit_evaluation
+ 3
S.P. Karthee I took different example
https://code.sololearn.com/WA9VqK0u0FPi/?ref=app
https://code.sololearn.com/WFVrdH9nWD2v/?ref=app
Check this article https://medium.com/@cpenarrieta/javascript-logical-operators-22ec8b5624af
+ 2
Thx! I got it!
expr1 || expr2
If expr1 can be converted to true, returns expr1; else, returns expr2.
expr1 && expr2
If expr1 can be converted to true, returns expr2; else, returns expr1.
+ 1
Yes! js is generally a strange language and you need to know its features.
https://www.sololearn.com/post/207103/?ref=app
+ 1
Thanks 🙂
0
Sololearn's one of challenge question
0
Angelo how js determines that John is true in the first alert, and the user is true in the second alert?
0
Ярослав Вернигора(Yaroslav Vernigora) they are not empty strings
True and false state of variables is not really about truth, it's more about 1s and 0s
0
I still didn't get it. where can I read about it? carefully study the operation of logical operators?
0
Guys, js logical operates are different from other languages???