vendredi 15 février 2019

if condition on node js

I'm Getting confused

I tried to have to have a two condition, in the first code I'm getting true answer seems the answer should be false.

var a = 'route 3';
if(a === 'route 1' || 'route 2'){
  console.log('true')
}else{
  console.log('false')
}

on the second code, I have two conditions and the first condition it seems true and the second must be false but i'm getting true answer. base on my understanding if the first condition is false the second condition will not be evaluated. can you enlighten my newbie mind why i'm getting true answered.

var a = 'route 1';
var b = 'route 3';

if(a === 'route 1' || 'route 2' && b === 'route 1' || 'route 2'){
  console.log('true')
}else{
  console.log('false')
}

thank you for the answer :)

Aucun commentaire:

Enregistrer un commentaire