All topics
Fundamentalsintermediate

Symbol and BigInt Primitives

Two newer primitive types: Symbol for guaranteed-unique property keys, and BigInt for integers beyond Number's safe range.

Symbol and BigInt are the two newest additions to JavaScript's set of primitive types, and while they show up far less often than strings or numbers, interviewers ask about them specifically to see whether your knowledge extends past the 'classic' primitives that existed since JavaScript's first version.

A Symbol is like a one-of-a-kind serial number stamped on an item — even if two items have the same product name, their serial numbers are guaranteed to be different. BigInt is like switching from a calculator with a fixed digit display to a full ledger book — you trade a bit of convenience for the ability to write numbers of any size without rounding.

Key Concepts

1
Symbol() creates a unique, immutable value that is guaranteed never to equal any other symbol, even one created with the exact same description string — Symbol('id') !== Symbol('id'). This uniqueness makes symbols ideal as object property keys when you want to avoid accidental name collisions, such as adding metadata to an object without risking overwriting an existing property, or implementing 'hidden' properties that don't show up in for...in loops or Object.keys(). The language itself uses well-known symbols internally — Symbol.iterator, for instance, is the exact mechanism that makes an object iterable with for...of and the spread operator.
Symbol()Symbol('id') !== Symbol('id')for...inObject.keys()Symbol.iterator
2
BigInt solves a different, more numeric problem: regular JavaScript number values are IEEE 754 doubles, which can only safely represent integers up to Number.MAX_SAFE_INTEGER (2^53 - 1) before precision loss creeps in. BigInt values, written with an n suffix (123n) or created via BigInt(123), can represent arbitrarily large integers exactly, which matters for cryptography, high-precision timestamps, or working with large IDs from systems like databases or blockchain platforms.
BigIntnumberNumber.MAX_SAFE_INTEGERn123n
3
The key gotcha with both: you cannot mix a BigInt and a regular number in arithmetic operations directly — 1n + 1 throws a TypeError — you must explicitly convert one side. And symbols cannot be implicitly converted to strings (` ${Symbol('x')} ` throws), which is a deliberate safety measure to prevent accidental stringification bugs.
BigIntnumber1n + 1TypeError