DEV Community

Discussion on: Is everything in JavaScript an Object?

Collapse
 
lilithkarapetyan profile image
Lilit Karapetyan

Thank you for bringing up this topic. I heard that phrase so much that it was confusing me at the beginning of my career.
I think this myth was created by the people working in other languages who started to get acquainted with JS just a little bit :)
I don't think it is even possible for the language to only have objects as its type (Correct me if I'm wrong).
The most important note here was about the optimization part. Please, please, do not try to do these kinds of micro-optimizations yourself :) The browser engines are designed to detect and optimize all the "normal" code flows. If you try to do some weird things, the browser engine will not detect recognizable patterns and will fail to optimize the performance.

Collapse
 
mayankav profile image
mayankav

@lilithkarapetyan Hello Lilit! To answer your question, I'd say it completely depends on how a particular language defines primitives and objects. In JS, objects are nothing more than collective key:value pairs and anything that is not an object is a primitive. Consider another language, maybe 'C', it maps primitive types much closer to the underlying microprocessor architecture (int, char etc..). Generally in computer science "primitives" emply atomic types but then every programming language can freely decide on how to implement their own basic building block. For example Python chose to keep objects at the atomic level. So yeah, it depends on the language.