-1

I want to run this if statement .

Help me to get the value of a.

var a =undefined ;

if(a=1 && a=2 && a=3)
{
console.log("Hello")}

else
 {console.log("Error")
}
slavoo
  • 5,798
  • 64
  • 37
  • 39

1 Answers1

-1

The issue is with this line if(a=1 && a=2 && a=3).Here the value is getting set to a instead of checking the condition

var a = undefined;

if (a === 1 && a === 2 && a === 3) {
  console.log("Hello")
} else {
  console.log("Error")
}

i want to run this if statement

a cannot be 1,2,3 at same time unless you are looking for something like this.Otherwise you can use or operator || instead of &&

brk
  • 48,835
  • 10
  • 56
  • 78
  • i don't want to change the if statement, every thing is allowed but i can't change the if statement – ABDUL REHMAN Mar 13 '18 at 04:54
  • @brk [Yes you can](https://tio.run/##y0osSyxOLsosKNHNy09J/f@/LLFIIdHWkCszTUEj0dZIU6GaizM5P684PydVLyc/XSNRk6v2/38A), just the operator precedence is wrong. – user202729 Mar 13 '18 at 05:02