Quick answer: JavaScript data types come in eight kinds — string, number, bigint, boolean, undefined, null, symbol and object — and you declare them with three keywords: const, let and the older var. Use const by default and let only when the value must be reassigned; avoid var. string, number, bigint, boolean, undefined, null, symbol and object.
Table of Contents
const, let and var
const name = "Ada"; // cannot be reassigned
let count = 0; // can be reassigned
count = count + 1;
var old = "avoid"; // function-scoped, legacy
const— a binding you will not reassign. Note that aconstarray or object can still have its contents changed; only the binding is fixed.let— a binding you will reassign, such as a counter or an accumulator.var— the pre-2015 form. It is function-scoped rather than block-scoped and can surprise you.Use it only in legacy code.
const list = [1, 2];
list.push(3); // allowed — contents changed, binding unchanged
// list = []; // TypeError — cannot reassign a const
The primitive JavaScript data types
| Type | Examples | Notes |
|---|---|---|
string | "hello", 'hi', backticks | Backticks allow interpolation |
number | 42, 3.14, NaN | One type for integers and decimals |
bigint | 9007199254740993n | For integers beyond the safe range |
boolean | true, false | Result of comparisons |
undefined | — | Declared but not assigned |
null | — | Deliberately empty |
symbol | Symbol("id") | A unique key |
object | {}, [], functions | Everything that is not a primitive |
number being one type is worth remembering: 1 === 1.0 is true, integer division produces decimals (7 / 2 is 3.5), and very large values lose precision, which is why bigint exists.
Strings and template literals
const user = "Ada";
const greeting = `Hello, ${user}!`; // template literal
const multi = `line one
line two`; // real multiline strings
const { length } = user; // 3
Prefer backticks with ${...} over concatenation with +. Interpolation keeps the message readable and avoids accidental type coercion when a value is not a string.
JavaScript data types: truthy, falsy and the equality question
Some values are treated as false in a condition. The list is short and worth memorising: false, 0, -0, 0n, "", null, undefined, NaN. Everything else is truthy — including empty arrays and empty objects, which surprises people.
if ([]) console.log("runs"); // empty array is truthy
if (0) console.log("skipped"); // 0 is falsy
"" == 0 // true — loose equality coerces
"" === 0 // false — strict equality does not
null == undefined // true
null === undefined // false
Use === and !== almost always. Loose == performs type coercion with a long rule table, and the only place it beats strict equality is the deliberate value == null check, which matches both null and undefined at once.
Number and string conversion between JavaScript data types
Number("42") // 42
Number("") // 0
parseInt("42px", 10) // 42 — stops at the first non-digit
String(42) // "42"
(42).toFixed(2) // "42.00"
[1,2,3].join(", ") // "1, 2, 3"
Prefer explicit Number() and String() over relying on implicit coercion. And remember that NaN is the only value not equal to itself: test it with Number.isNaN(value), never with ===.
Next in the series: functions. To learn JavaScript properly with a mentor, Ampersand Academy teaches web development one-to-one.
Frequently asked questions
When should I use const instead of let in JavaScript?
Use const by default. Switch to let only when you must reassign the variable, such as a counter. const still allows you to change an array’s or object’s contents; it only prevents rebinding.
What is the difference between == and === in JavaScript?
=== compares value and type without coercion. == coerces the operands to a common type first, which produces surprising results such as empty string equalling zero. Prefer === and !==.
What are the falsy values in JavaScript?
false, 0, -0, 0n, empty string, null, undefined and NaN. Everything else is truthy, including empty arrays and empty objects, which often surprises beginners.
Why is typeof null equal to object?
It is a long-standing bug from the language’s first version that cannot be fixed without breaking the web. Check for null explicitly with value === null instead of relying on typeof.
How do I check for NaN in JavaScript?
Use Number.isNaN(value). NaN is the only value not equal to itself, so value === NaN is always false and will never detect it.

