Data Types and Operators
Every value in JavaScript has a type, and the type determines what you can do with it.
JavaScript
Common types
| Type | Example |
|---|---|
| number | 16, 19.99, -3 |
| string | "Space Quest" |
| boolean | true / false |
Operators
- Arithmetic:
+ - * /work on numbers as you'd expect.+on two strings joins them instead of adding. - Comparison:
===checks if two values are equal (strictly, without converting types),!==checks if they're not equal,<,>,<=,>=compare numbers.
JavaScript
Why === and not ==
JavaScript also has ==, which converts types before comparing ("5" == 5 is true), that hidden conversion causes subtle bugs. Prefer ===/!==, which compare exactly what you wrote.