Why does (“” && false) evaluate to “”? [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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.





it returns the first falsy value, or the last of all truthy values.
– Nina Scholz
yesterday





&& 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






Popular posts from this blog

Stripe::AuthenticationError No API key provided. Set your API key using “Stripe.api_key = ”

CRM reporting Extension - SSRS instance is blank

Keycloak server returning user_not_found error when user is already imported with LDAP