Or, What it really means when people say “Everything in JavaScript is an object”
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 Teasers.
Previous Head First JavaScript Programming Teasers Episodes
- Part 1: A Teaser from Head First JavaScript Programming
- Part 2: Getting JavaScript in your pages, the right way
- Part 3: What makes JavaScript different?
- Part 4: Dive into JavaScript
- Part 5: JavaScript variables and types
- Part 6: Using the console
- Part 7: JavaScript Scope
- Part 8: Working with the DOM
- Part 9: Keeping track of this in your JavaScript code