Yes, primitive values in JavaScript are immutable: once a string, number, boolean, undefined, null, symbol or BigInt value exists, it cannot be changed. Operations that look like changes, such as str + "!" or n++, produce a new value, and a variable can only be reassigned to point at that new value.
Immutability applies to values, not to variables. A variable declared with let can be reassigned, but the primitive it held before is not altered. Objects, arrays and functions are different: they are mutable reference values.
An immutable value cannot be modified in place after it is created. JavaScript has seven primitive types:
| Type | Example | Notes |
|---|---|---|
string | "hello" | Sequence of UTF-16 code units |
number | 42, 3.14 | IEEE 754 double |
bigint | 123n | Arbitrary-size integers |
boolean | true | |
undefined | undefined | Unassigned value |
null | null | Intentional absence |
symbol | Symbol("id") | Unique identifier |
You can confirm each of them with typeof, remembering that typeof null returns "object" for historical reasons even though null is a primitive.
Trying to assign to a character of a string does nothing in sloppy mode and throws a TypeError in strict mode (which includes ES modules and classes).
Every string method, including replace, slice, trim and toUpperCase, returns a new string and leaves the original alone.
Arithmetic never modifies an existing number. It computes a new one that you can store.
The same holds for BigInt (1n + 1n creates 2n), booleans (!true creates false) and symbols (each Symbol() call creates a distinct value that never changes).
This is the point that confuses most beginners. When you write x = x + 1, you are not changing the number. You are making the variable x hold a different value. The difference shows up with const:
const prevents rebinding the variable. Immutability is a property of the value itself. Because primitives are immutable, a const that holds a primitive can never change at all.
Immutability makes primitive assignment safe: the copy cannot affect the original, because neither value can ever be edited.
Objects are mutable, and const does not stop that. To make an object shallowly unchangeable, use Object.freeze(). For deep immutability you must freeze nested objects yourself or use a library or immutable update patterns such as spread syntax and structuredClone().
Writing "abc".length works because JavaScript temporarily wraps the primitive in a String object to look up the property. Assigning a property to a primitive therefore has no lasting effect.
Avoid creating wrappers with new String(), new Number() or new Boolean(). They are objects, so typeof new String("a") is "object" and comparisons behave unexpectedly.
Yes. String, number, bigint, boolean, undefined, null and symbol are all immutable.
Reassignment changes which value the variable holds. It does not change the old string. The old value stays unchanged until garbage collection frees it.
const make a value immutable?No. const only prevents rebinding the variable. A const object can still be mutated, while a const primitive cannot change because primitives are immutable.
Each concatenation creates a new string, but modern engines optimise this heavily. For building very large strings from many pieces, collecting parts in an array and calling join("") is still a clear pattern.
Primitive values in JavaScript are immutable. Operations create new values, assignment copies values, and const only controls rebinding. Objects and arrays are mutable references, so use Object.freeze() or copy-on-update patterns when you need immutability there.