FSM Full Stack Masterclass
Platform under construction
JavaScript course badge

Values & Types

Intermediate

Primitive Types

Primitive values are the simple immutable values of JavaScript: null, undefined, boolean, number, bigint, string and symbol.

const name = "User A";      // string
const tasks = 4;       // number
const paid = false;       // boolean
const id = Symbol("id");  // symbol

Values & Types

Primitive values are simple, immutable building blocks.

JavaScript has primitive values and objects. Primitive values are not objects, cannot be mutated directly and are represented as direct language values.

The primitive types are null, undefined, boolean, number, bigint, string and symbol. Everything else is object-like, including arrays, dates, regular expressions and functions.

Primitives can feel object-like because JavaScript temporarily wraps many primitive values when you call methods. That is why "hello".toUpperCase() works even though strings are primitive.

undefined

A missing value produced by JavaScript in many default situations.

null

An intentional empty value, often used to say no object or no selected value.

number and bigint

Numbers handle general numeric work. BigInt handles very large integers.

string, boolean, symbol

Text, true/false logic and unique property keys.

Examples

Good type handling makes JavaScript predictable.

Use primitives for the right meaning

const userName = "User A";
const itemCount = 4;
const hasPaid = false;
const selectedOption = null;
const databaseId = 9007199254740993n;
const privateKey = Symbol("record-id");

Stringly typed values hide meaning

const itemCount = "4";
const hasPaid = "false";
const selectedOption = "";

// These look simple, but every later calculation must guess intent.

Rules that matter

Types are not paperwork. They are behavior.

JavaScript lets values move flexibly, but professional code keeps meaning clear. Convert at boundaries, validate input and choose values that represent the real idea.

Use strings for text

Do not store structured data as one long string if an object or array would be clearer.

Use booleans for true or false state

Avoid "yes", "no", "true" and "false" strings when the value is logical.

Use numbers for ordinary math

Prices, counters and measurements usually start as number values.

Use BigInt only for large integers

BigInt cannot represent fractions and cannot be freely mixed with number arithmetic.

Use null intentionally

null should mean explicitly empty, not accidentally missing.

Use symbols for uniqueness

Symbols are useful for unique keys and advanced object protocols.

Production thinking

Data quality starts with value quality.

Why does this matter?

Types are meaning. If the type matches the real concept, the code becomes easier to read and harder to misuse.

Accessibility

Primitive state often controls labels, validation messages and disabled states. Wrong types can create wrong feedback.

Production note

Production data should be normalized at boundaries: form input is text, JSON has limits and databases may return strings for large numbers.

SEO note

Type mistakes in rendering code can show wrong content, empty values or broken template output.

Live code lab

Change the HTML, CSS or JavaScript and run the result.

The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.

Mini assignment

Try this now.

  • Add a normal object to the values array.
  • Add an array to the values array and inspect typeof.
  • Replace false with the string "false" and compare the type.

Practice assignment

Do this before moving to the next topic.

  1. Write one example for every primitive type.
  2. Explain why strings are immutable.
  3. Find one place where form input must be converted from string to number.

Try it yourself

Inspect primitive types

Live preview

Self-check

Before you continue, prove that you understand Primitive Types.

Intermediate

Say the answer in plain language. If you can explain the value behavior, the code becomes much easier to debug.

  1. Can you name the primitive types in JavaScript?
  2. Can you explain why arrays are not primitive values?
  3. Can you explain why "false" is not the same as false?
  4. Can you explain what immutable means?
  5. Can you explain why BigInt is not just a bigger Number?