16

When Primitives Behave Like Objects

In this Chapter

  • Get a deeper understanding of how primitives and objects work

  • Understand that even primitives have object-like traits

  • Wonder how JavaScript ever got to be so popular

In Chapter 14, “Strings,” and less so in Chapter 12, “Of Pizza, Types, Primitives, and Objects,” we got a sneak peek at something that is probably pretty confusing. I’ve stated many times that primitives are very plain and simple. Unlike objects, they don’t contain properties that allow you to fiddle with their values in interesting (or boring) ways. Yet, as clearly demonstrated by all the stuff we can do with strings, our primitives seem to have a mysterious dark side to them. Look at the following example:

Get Javascript Absolute Beginner's Guide, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.