5.4 Conditionals If statements

  1. let billHasBeenPaid = false;
  2. if (!billHasBeenPaid) {
  3. console.log(“Your bill is due soon!”);
  4. }

I’m curious why the ! has been added inside the brackets on line 3 if the variable on line 1 does not include this? I am just starting the reading in chapter 5.4 but I’m seeing this ! added in all the examples. When I run the code in Repl.it, the code will not run without the !, so I can tell that it is necessary, but I don’t see anything in the reading explaining it. Any insight would be great. Thank you.

I’ve just realized that in this example they are using the (!) as the NOT operator, so I’m interpreting this statement to read, (!billHasBeenPaid) is NOT false (aka true) so that’s why the code executes. At least that’s my interpretation, any other comments are appreciated.

You are correct. ! is negating the value of your variable & since it’s a boolean set to false, it becomes true so the code block inside your if statement executes.