Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)

Can anyone help me with the operator in JavaScript like "||" which returns the value as -1 for the below code:

var test = 0 || -1 ;

console.log(test);

Any help would be appreciated.

1 Answer

0 votes
by (26.7k points)

Basically, || operator stands for logical OR.

So, it will return as -1. Whereas, if it was something like this:

var test  = 0 || false || undefined || "" || 2 || -1

Then, it will return 2.

I hope this will help.

Want to become a Java Expert? Join Java Certification now!!

Want to know more about Java? Watch this video on Java Tutorial for Beginners | Java Programming:

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...