Why does (“” && false) evaluate to “”? [duplicate]
Clash Royale CLAN TAG#URR8PPP
– Paulpro
yesterday
The linked question is findable when searching “js and operator returns empty string”.
– Xufox
yesterday
Why does (“” && false) evaluate to “”? [duplicate]
This question already has an answer here:
Assume you have the following lines:
const input = "";
if(input && input !== "")
I would expect this to return false, instead it returns an empty string. The easy fix is to check if 'input' is not equal to null, but I'm curious as to why
("" && false)
evaluates to ""
This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.
&&
evaluates to it's left operand iff. it's left operand is falsey. ""
is falsey, so "" && X
evaluates to ""
no matter what expression X is.– Paulpro
yesterday
&&
""
"" && X
""
The linked question is findable when searching “js and operator returns empty string”.
– Xufox
yesterday
it returns the first falsy value, or the last of all truthy values.
– Nina Scholz
yesterday