Reason : Non empty string is always true in JavaScript

In First code if(a === ‘route 1’ || ‘route 2’) in this condition the second condition is always true. So,if(a === ‘route 1’ || ‘route 2’) always return true and condition should be like if(a === ‘route 1′ || a ===’route 2’) for desired output.

In Second code if(a === ‘route 1’ || ‘route 2’ && b === ‘route 1’ || ‘route 2’) in this condition second condition with OR is always true So,if(a === ‘route 1’ || ‘route 2’ && b === ‘route 1’ || ‘route 2’) always return true and condition should be like if(a === ‘route 1’ || a === ‘route 2’ && b === ‘route 1’ || b === ‘route 2’) for desired output.

Need Help With Node Development?

Work with our skilled Node developers to accelerate your project and boost its performance.

Hire Node.js Developers

Support On Demand!

Related Q&A