-4

Why does '' && 'haha' evaluate to ''

and why does 'haha' || '' evaluate to 'haha' in JavaScript?

I would think the first one evaluates to false and the second one evaluates to true

  • 2
    logical AND, logical OR. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_AND - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_OR – GrafiCode Jun 02 '22 at 12:11
  • 1
    There is plenty to be found on the internet, i suggest you do some research, It has some funny cases. In short: A string is truthy, so the first will always match. – Martijn Jun 02 '22 at 12:11
  • No. These dumazz operators don't return true or false. They return one of the operands. – Salman A Jun 02 '22 at 12:12
  • 1
    why are you reversing the comparisons? but read the documentation; `&&` returns the first falsy value, and `||` returns the first operand if truthy, otherwise the second regardless of its value. – pilchard Jun 02 '22 at 12:14

0 Answers0