
JavaScript Data Types
๐งพ JavaScript Data Types: The Foundation That Should Not Be Overlooked
We spend hours mastering libraries, frameworks, and tools. But how often do we revisit the fundamentals?
Data types are the foundation of everything in JavaScript.
Yet many developers treat them as "that thing I learned in week one" and never think about again.
And then bugs happen.
Comparisons break. APIs return unexpected values. Type coercion does something bizarre.
Understanding the data types is not optional. It's the difference between shipping bugs and shipping confidence.
#JavaScript #DataTypes #Primitives #Objects #WebDevelopment #CodingTips #Programming #Frontend #JavaScriptTips #SoftwareEngineering
JavaScript data types
JavaScript can work with primitive types (number, string, boolean, null, undefined, symbol, bigint) and objects (arrays, functions, plain objects).
| Type | Category | Description |
|---|---|---|
number | Primitive | Numeric values, including integers and floats. |
string | Primitive | Textual data wrapped in quotes, backticks, or double quotes. |
boolean | Primitive | Logical values: true or false. |
null | Primitive | Intentional absence of any value. |
undefined | Primitive | Variable declared but not assigned a value. |
symbol | Primitive | Unique, immutable identifier. |
bigint | Primitive | Arbitrary-precision integers. |
object | Structural | Collections of key-value pairs, arrays, functions, dates, etc. |
number
Represents both integers and floating-point values.
const age = 30;
const price = 19.99;
const notANumber = NaN;
const infinity = Infinity;
typeof age; // "number"
typeof NaN; // "number"string
Immutable textual data.
const name = "Ada";
const greeting = 'Hello'; // prettier-ignore
const template = `Hi, ${name}`;
typeof name; // "string"boolean
Logical type with only two values.
const isActive = true;
const isAdmin = false;
typeof isActive; // "boolean"null
Represents an absence of value.
const user = null;
typeof user; // "object" (historical quirk)
user === null; // truetypeof null gives "object". This is a long-standing JavaScript quirk.
Instead, use value === null to check for null.
undefined
A variable that has been declared but not assigned a value.
let score;
typeof score; // "undefined"
score === undefined; // truesymbol
Unique and immutable value, often used as object keys.
const id = Symbol("id");
const anotherId = Symbol("id");
id === anotherId; // falsebigint
For integers larger than Number.MAX_SAFE_INTEGER.
const huge = 9007199254740993n;
const alsoHuge = BigInt(9007199254740993);
typeof huge; // "bigint"object
Collections of properties. Includes plain objects, arrays, functions, dates, and more.
const person = { name: "Ada", age: 30 };
const numbers = [1, 2, 3];
const greet = () => "hello";
typeof person; // "object"
typeof numbers; // "object"
typeof greet; // "function"
Array.isArray(numbers); // trueFull-Stack AI Developer Roadmap
From HTML & CSS to working with AI models, all in one structured roadmap.