+ 2
Why is the answer "John" if the question alert("John" || "user")? And what does || actually mean in JavaScript?
When I am challenging someone, there's a question like alert("John" || "user"). If I check the correct answer, it is answer "John", and I thought the answer is only true and false. What is that??
2 odpowiedzi
+ 2
If the first argument is true, use this, else use second argument.
See this https://stackoverflow.com/questions/37318146/javascript-logical-operators-and-strings-numbers
+ 1
|| simply means or. And it picks the first true value. For it to pick "user" the first value has to be false, NaN, Undefined, null etc.