Why does the function return false?

Angel Politis

I'm trying to shorten out the following code:

var a = 0, b = 0;

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

So, I thought something like the following would do:

var a = 0, b = 0;

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

Initially, I thought that such syntax would throw an error, but apparently it returns false. Why does a === b === 0 return false?

Pointy

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

One can imagine a programming language that would understand a chain of expressions connected by == or === or whatever, meaning that all values should be compared in one big "group equality" comparison. JavaScript is not such a language, however.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Why does my ajax function return false?

Why does the any() function return False?

Why does this .every() function return true and then false?

Why does function sometimes return 0 and sometimes return false?

Why does this return False

Why does False==False in [False] return True?

Why does my getColor function always return false?

Why does isPrototypeOf() return false?

In JQuery, why does $(this) == $(this) return false?

Why does IsGenericTypeDefinition return false?

Why does "not(True) in [False, True]" return False?

Why does '() is ()' return True when '[] is []' and '{} is {}' return False?

Why does my javascript function return true when it should return false

Why doesn't std::is_invocable_r_v<void, TFun> return false if the function does not return void

In C, why does this function return false when conditions are met for it to return true?

Why does false && (false)?false:true return true

Why does DOMXPath->evaluate() return false

Why does an undefined operand not return false?

Why does this boolean expression return False?

Why does my `if(result !== "false")` return true?

Why does ... == True return False in Python 3?

Why does %in% return false when matching string?

Why does comparing objects values return false?

Why does instanceof return false for some literals?

Why does include? for Ruby return false?

Why does "foo".class === String return false?

Why does HasNext() return false, when

Simple Q Javascript - Why does this return false?

Why does this if statement of query return false?