CONTROL FLOW Comparison Operators



I’m not having a problem per se but I wanted to know about the if (!hungerLevel > 7) statement. Is the ! evaluating the truthiness of hungerLevel variable or the whole statement?

Thanks you!

let hungerLevel = 10;

if (!hungerLevel  > 7) {
  console.log(`Time to eat!`);
} else {
  console.log(`We can eat later!`);


! simple changes false to true and versa, hungerLevel > 7 is true given hungerLevel = 10, so then we get:

if (!true)

which becomes false


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.