This content originally appeared on DEV Community and was authored by Turkan İsayeva
While this is a well-known phrase among JS developers, it’s not utterly true.
JavaScript has two main categories of data types:
1⃣. Primitive Types – string, number, boolean, null, undefined, symbol, bigint
2⃣. Object Types – Object, Array, Function, Date, RegExp, etc.
So Why Do We Say “Everything is an Object”?
Even though primitives like strings and numbers are not
objects, they can behave like objects. This is because JavaScript temporarily wraps them in their corresponding object wrapper when you try to access a property or call a method.
let name = “Turkan”;
console.log(name.length); // 6
Here, “Turkan” is a primitive string, but JavaScript internally wraps it in a String object, so you can use .length and other methods like .toUpperCase().
But Remember:
• Primitives are not objects.
• typeof null === “object” is a historical bug in JavaScript. null is not an object.
• Only actual object types can store methods and properties persistently.
So,
“Everything in JavaScript behaves like an object, but not everything is an object.”
Understanding this distinction helps you write cleaner and more predictable code.
This content originally appeared on DEV Community and was authored by Turkan İsayeva