What it really means when people say “Everything in JavaScript is an object”

A new mantra for your next (programming) meditation session.

When you begin programming with JavaScript you might run across books, tutorials, and people who say “Everything in JavaScript is an object.” While it’s not 100% true (not *everything* is an object), it is *mostly* true. And sometimes this can be a bit surprising.

For instance, to most people functions and objects look and act completely different. And in many languages, functions and objects *are* completely different. However, in JavaScript, a function is an object. This can take a bit of concentrated attention to get your head around, but it’s an important concept because it’s the secret behind another big topic in JavaScript: functions as first class values.

And what about values like numbers, booleans and strings? One of the first things you learn when you pick up a book or tutorial on JavaScript is that these kinds of values are “primitive” values; in other words, they’re definitely *not* objects. And yet, you’ll quickly find out that in JavaScript, sometimes they *are* objects!

So bend your mind a bit, and immerse yourself in the world of objects to learn how, in JavaScript, (almost) everything is an object in this installment of Head First JavaScript Programming.

tags: , , , , , , , , , , , , , ,