Autoboxing Primitive Types in JavaScript

Share this video with your friends

Send Tweet

Primitive values by rule are not objects. However when we treat a primitive type like an object, such as getting the .length of a string, JavaScript will wrap that primitive type into an object. This new object is then linked to the corresponding built-in .prototype, so that we can utilize prototype methods on primitive types.

Michael
Michael
~ 5 years ago

But there are a lot of methods on strings, ie padEnd.

Rafael Melo
Rafael Melo
~ 5 years ago

"Primitive values by rule are not objects. However when we treat a primitive type like an object, such as getting the .length of a string, JavaScript will wrap that primitive type into an object. "

Joey Ng'ethe
Joey Ng'ethe
~ 4 years ago

@tyler, what tool/extension do you use to show the console.log values inside the editor?

~ 3 years ago

SO THAT'S WHY I CAN'T CALL STRING.LENGTH. That always bugged me, coming from Ruby.