โค Like
๐Ÿ”– Save
๐Ÿ”— Share
Eric Hu
Eric Hu

JavaScript Data Types

@thedevspaceio

๐Ÿงพ 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).

TypeCategoryDescription
numberPrimitiveNumeric values, including integers and floats.
stringPrimitiveTextual data wrapped in quotes, backticks, or double quotes.
booleanPrimitiveLogical values: true or false.
nullPrimitiveIntentional absence of any value.
undefinedPrimitiveVariable declared but not assigned a value.
symbolPrimitiveUnique, immutable identifier.
bigintPrimitiveArbitrary-precision integers.
objectStructuralCollections of key-value pairs, arrays, functions, dates, etc.

number

Represents both integers and floating-point values.

js
const age = 30;
const price = 19.99;
const notANumber = NaN;
const infinity = Infinity;
 
typeof age; // "number"
typeof NaN; // "number"

string

Immutable textual data.

js
const name = "Ada";
const greeting = 'Hello'; // prettier-ignore
const template = `Hi, ${name}`;
 
typeof name; // "string"

boolean

Logical type with only two values.

js
const isActive = true;
const isAdmin = false;
 
typeof isActive; // "boolean"

null

Represents an absence of value.

js
const user = null;
 
typeof user; // "object" (historical quirk)
user === null; // true

typeof 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.

js
let score;
 
typeof score; // "undefined"
score === undefined; // true

symbol

Unique and immutable value, often used as object keys.

js
const id = Symbol("id");
const anotherId = Symbol("id");
 
id === anotherId; // false

bigint

For integers larger than Number.MAX_SAFE_INTEGER.

js
const huge = 9007199254740993n;
const alsoHuge = BigInt(9007199254740993);
 
typeof huge; // "bigint"

object

Collections of properties. Includes plain objects, arrays, functions, dates, and more.

js
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); // true

Full-Stack AI Developer Roadmap

From HTML & CSS to working with AI models, all in one structured roadmap.

@thedevspaceio
www.thedevspace.io