Sobes.tech
Junior

What do you know about primitives in JavaScript?

sobes.tech AI

Answer from AI

In JavaScript, primitives are simple, immutable data types that are stored directly in the stack rather than in the heap. The main primitives include:

  • string — strings
  • number — numbers
  • bigint — large integers
  • boolean — logical values
  • undefined — default value for undeclared variables
  • null — a special value indicating "no value"
  • symbol — unique identifiers

Primitives do not have methods and properties themselves, but JavaScript temporarily wraps them in corresponding object wrappers to call methods.

Example:

let str = "hello";
console.log(str.toUpperCase()); // "HELLO"

Primitive values are immutable, meaning operations on them create new values rather than modify existing ones.

It is also important to understand that when comparing primitives, their values are compared, not references, unlike objects.