# Type coercion and equality operators

*JavaScript Developer Study Guide · Variables, Types, and Collections · Last updated October 16, 2026 · https://www.certifyforce.com/study-guide/javascript-developer/variables-types-and-collections/type-coercion-and-equality-operators*

When JavaScript converts types on its own: + concatenation vs arithmetic, how objects become primitives through valueOf and toString, == vs === vs Object.is, relational comparison of strings, typeof surprises, explicit conversion with Number, String and Boolean, and the NaN checks that actually work.

- Certification: Salesforce JavaScript Developer
- Exam section: Variables, Types, and Collections
- Study guide: https://www.certifyforce.com/study-guide/javascript-developer

**Official exam objective:**

> Given a scenario or example, demonstrate awareness of type coercion and its effects.

## What the exam expects

- Predict the result of `+`, `-`, `*` and `+=` when one operand is a string, `null`, `undefined`, an array or an object.
- Evaluate `==`, `===` and `Object.is()` for mixed types, `null`/`undefined`, `NaN` and `-0`, and know that `switch` uses strict equality.
- Predict `<` and `>` when both operands are strings versus when one is a number.
- Convert explicitly with `Number()`, unary `+`, `String()` and `Boolean()`, and test for `NaN` with `Number.isNaN()`.
- Know the `typeof` results that surprise people: `null`, `NaN`, arrays and functions.
- Key terms: **coercion** (an implicit, automatic type conversion); **explicit conversion** (calling `Number()`, `String()` or `Boolean()` yourself); **primitive coercion** (turning an object into a primitive by `valueOf()` or `toString()`); **loose equality** (`==`, converts types first); **strict equality** (`===`, never converts).

## Key facts

| Fact | Detail | Source |
|---|---|---|
| `'5' + 3` | `'53'`: a string operand makes `+` concatenate | [Addition (+)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition) |
| `'5' - 3` | 2: `-` always converts to numbers | [Subtraction (-)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction) |
| `null` / `undefined` as numbers | 0 / `NaN` | [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number) |
| `+` and `==` on objects | `valueOf()` before `toString()` | [JavaScript data types and data structures](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures) |
| `String(obj)` and template literals | `toString()` before `valueOf()` | [JavaScript data types and data structures](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures) |
| `null == undefined` | `true`; `null == 0` is `false` | [Equality (==)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality) |
| Boolean in `==` | Converted to 1 or 0 first | [Equality (==)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality) |
| `NaN === NaN` | `false`; `Object.is(NaN, NaN)` is `true` | [Equality comparisons and sameness](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness) |
| `switch` matching | Strict equality | [switch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch) |
| `'10' < '9'` | `true`: two strings compare by code unit | [Less than (<)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than) |
| `typeof null` | `"object"` | [typeof](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof) |
| `Number.isNaN('abc')` | `false`: no coercion | [Number.isNaN()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN) |

## Check yourself

- Why does `'10' < '9'` return `true` while `'10' < 9` returns `false`?
- When does `price + ''` use an object's `valueOf()` instead of its `toString()`?
- What does `typeof null` return?
- Why is `Number.isNaN()` safer than `isNaN()` for validation?
- What do `Number('')` and `Number(undefined)` return?

## Sources

- [Equality comparisons and sameness](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Equality_comparisons_and_sameness)
- [Type coercion](https://developer.mozilla.org/en-US/docs/Glossary/Type_coercion)
- [Equality (==)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Equality)
- [Addition (+)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Addition)
- [Subtraction (-)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Subtraction)
- [JavaScript data types and data structures](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Data_structures)
- [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)
- [String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)
- [Boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)
- [Less than (<)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Less_than)
- [typeof](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof)
- [isNaN()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN)
- [Number.isNaN()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/isNaN)
- [switch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/switch)

## About the full unit

The "Core concepts", "Exam traps" and "Worked scenario" sections of this unit, its 10 linked practice questions, and unlimited timed mock exams are included with the JavaScript Developer pack (USD $19): https://www.certifyforce.com/practice-exams
