Is Everything Object In Javascript?

let str = "apple";
console.log(str.length) //5

One line 1, variable str is assigned a string value. On line 2 we console log length of string value by accessing length properties. But string is a primitive value hence do not have properties and method so how can we use .length property on it.

Does this mean everything is a object  in javascript?

No, not every value is object in javascript. Primitive values such as strings and number can behave like object but they are not object.

In javascript when we use properties and methods on primitive value, it implicit coerces it into object because we are treating primitive value like a object.It will wraps primitive value in an object. This is called boxing.

In above example, when we used .length property, variable str was first converted into object and length property was accessed.