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.

Support On Demand!

Node