DEV Community

Discussion on: 19 JavaScript Questions I Have Been Asked Most In Interviews

Collapse
 
nahueldev profile image
Nahuel

"Everything is an object"
No, primitives aren't object.

Collapse
 
sachininsuredmine profile image
sachin-insuredmine

yeah but they are wrapped in object

Collapse
 
jonrandy profile image
Jon Randy 🎖️

Yep, you can add methods to numbers

Collapse
 
merthod profile image
Merthod

Primitives are called that basically because they are represented as is in the underlying C++ code, or bytecode.

But in JS, everything is an object. undefined, for example is a property that lives in the window object of a browser. Naturally, in JS primitives are wrapped in their [forgot the ECMA-naming-convention] object. But as long as you assign a primitive to a variable or use () or return it (thus wrapping it in an object), it becomes an object on its own automatically because of the prototypical nature of the language.