DEV Community

Vijay SRJ
Vijay SRJ

Posted on

The case of the binary logical operators '&&' and '||' in Javascript

In Javascript the binary logical operators '&&' and '||' behave differently compared to the same operators in a programming language like Java.
This is because javascript binary logical operators can return even a number or a string, not just true or false!
And again this is possible because Javascript has this concept of 'Truthy' and 'Falsy'.

Anything of the below is considered as false by javascript:
''
false
NaN
null
undefined

Everything else is considered as true

Here is a short post on how the above concept affects the binary logical operators in javascript:

https://fullstackdeveloper.guru/2021/04/21/how-the-binary-logical-operators-and-differs-in-javascript-from-java/

Top comments (0)