DEV Community

Rudra Pratap
Rudra Pratap

Posted on • Edited on

Primitives in Javascript

Primitives are the data that are not objects and they have no methods and properties.
All primitives are immutable. They reside in the call stack while execution of the program, unlike the objects that reside in memory heap.

There are seven primitive data types in Javascript

  1. Number
  2. String
  3. Boolean
  4. Null
  5. Undefined
  6. Symbol (ES2015)
  7. BigInt (ES2020)

Everything in Javascript is either primitive or object

JavaScript only has primitive types and objects.

Primitive types are boolean, null, undefined, bigint, number, string, and symbol.

What differentiates a primitive from an object is that primitives do not have any properties or methods; however, you'll note that 'foo'.toUpperCase() evaluates to 'FOO' and does not result in a TypeError. This is because when you try to access a property or method on a primitive like a string, JavaScript will implicitly wrap the primitive type using one of the wrapper classes, i.e. String, and then immediately discard the wrapper after the expression evaluates. All primitives except for null and undefined exhibit this behaviour.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay