-3
$(document).keypress(function() {
  if (!started) {
    $("#level-title").text("Level " + level);
    nextSequence();
    started = true;
  }
});

I don't understand what does (!started) do inside the if condition.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • 6
    Checks if it is not started. Check out [this page on logical NOT operator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Logical_NOT) as well. – kelsny Sep 14 '22 at 16:33
  • 6
    It's essentially equivalent to `if (started == false)` – Barmar Sep 14 '22 at 16:35
  • 1
    Does this answer your question? [What does this symbol mean in JavaScript?](https://stackoverflow.com/questions/9549780/what-does-this-symbol-mean-in-javascript) – user3840170 Sep 14 '22 at 16:58

1 Answers1

0

Assuming started is a Boolean variable (contains true or false) that represents the state of something that could be started or stopped, then the Statement,

if (!started) {

is asking IF NOT STARTED THEN... ELSE...

! represents the Not Operator and started represents the variable. This is a logical condition where started can be true or false. If started is true, then !started is false. If started is false then !started is true.

Here is another way the Not Operator can be used.

var started = true;
started = !started;
console.log(started); // false
Twisty
  • 30,304
  • 2
  • 26
  • 45