Autoboxing Primitive Types in JavaScript

InstructorTyler Clark

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
~ 5 years ago

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

Rafael Melo
~ 4 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
~ 4 years ago

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

~ 2 years ago

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