In Javascript, when using an if statement to compare zero and not false with triple equal signs, why is not false equal to false?

I’m creating a typing test in Javascript. When the user presses the keyboard button, the typing test begins if zero keys have been pressed previously. If textEnteredLength (keys pressed) is === 0 and !timerRunning is equal to not false. Why does this function run? 0 === not false, is not a true statement, right?

    var timerRunning = false;
    
    function start() {
    let textEnterdLength = testArea.value.length;
    if (textEnterdLength === 0 && !timerRunning){
        timerRunning = true;
        interval = setInterval(runTimer, 10);
    }

265 thoughts on “In Javascript, when using an if statement to compare zero and not false with triple equal signs, why is not false equal to false?”

  1. Today, I went to the beach with my kids. I found a sea shell and gave it to my 4 year old daughter and
    said “You can hear the ocean if you put this to your ear.” She placed the shell
    to her ear and screamed. There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is completely off topic but I had to tell someone!

    Reply

Leave a Comment