Why does the function return false?

I am trying to shorten the following code:

var a = 0, b = 0;

function() {
    return a === 0 && b === 0; // returns 'true'
}

So, I thought something like the following:

var a = 0, b = 0;

function() {
    return a === b === 0; // returns 'false'
}

At first, I thought that such a syntax would cause an error, but apparently it returns . Why returns ? false a === b === 0 false

+4
source share
2 answers

An expression is a === b === 0interpreted as if it were written (a === b) === 0. The result false, because it (a === b)gives true, truenot from ===to 0.

, , == ===, - , , " ". JavaScript .

+10

Source: https://habr.com/ru/post/1651938/


All Articles