# Multiple Strict Equality Comparisons In A Single Line

## 18 January 2016 - 1 answer

I have the following JavaScript code:

``````var a = 1;
var b = 1;
a === 1        // evaluates to true
b === 1        // evaluates to true
a == b == 1    // evaluates to true
a === b === 1  // evaluates to false
``````

Why does `a === b === 1` evaluate to `false`?

``````a == b == 1
``````

is evaluated as

``````((a == b) == 1)
``````

Since `a == b` is `true`, the expression becomes

``````true == 1
``````

Since `==` does type coercing, it converts `true` to a number, which becomes 1. So the expression becomes

``````1 == 1
``````

That is why this expression is `true`. You can confirm the boolean to number conversion like this

``````console.log(Number(true));
// 1
console.log(Number(false));
// 0
``````

Similarly,

``````a === b === 1
``````

is evaluated as

``````((a === b) === 1)
``````

so

``````truesotrue === 1
Since === doesn't do type coercion (as it is the strict equality operator), this expression is false.``````
`Ad`
` (adsbygoogle = window.adsbygoogle || []).push({});`
`source: stackoverflow.com`

## `Related Questions`

• `→ How to update data attribute on Ajax complete`
• `→ October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear`
• `→ Octobercms Component Unique id (Twig & Javascript)`
• `→ Passing a JS var from AJAX response to Twig`
• `→ Laravel {!! Form::open() !!} doesn't work within AngularJS`
• `→ DropzoneJS & Laravel - Output form validation errors`
• `→ Import statement and Babel`
• `→ Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined`
• `→ React-router: Passing props to children`
• `→ ListView.DataSource looping data for React Native`
• `→ Can't test submit handler in React component`
• `→ React + Flux - How to avoid global variable`
• `→ Webpack, React & Babel, not rendering DOM`
`Ad`
` (adsbygoogle = window.adsbygoogle || []).push({});`