As you learn more more about other programming languages, you'll come to realize that they each have a point of view — themes and patterns that may be unique to them that will become more obvious as you become familiar with them. Consider some of your favorite authors or artists; many of them likely have a certain style that gives their work away without it being explicitly stated:
- For example, many Quentin Tarantino movies involve shootouts and pop culture references from bygone years
- Maria Callas' bel canto wedding of emotional tension with vocal interpretation
- Dickens novels usually feature noble, but poor, people showing virtue against a cruel world
- Rothko paintings are very large in scope and seem designed to dominate your emotions
Like these creators, JavaScript has a fundamental point of view:
JavaScript loves functions.
JavaScript makes this love clear from our first encounter with functions. It
makes functions first-class data. Functions, that is to say, "frozen" work,
can be passed around like "primitive" data (String
s or Integer
s, etc.).
JavaScript passes around its functions, shoves them to Arrays
, makes them
accessible via a key in an Object
, and more. Few other programming
languages share this point of view.
Who learns another language learns another mind — Charlemagne
Because of JavaScript's uncommon love for functions, developers sometimes get stymied by difficult bugs and they blame the language for it. This is unfortunate. Don't fall victim to this pattern of behavior with JavaScript (or, with much of anything in life): seek to understand its point of view and appreciate the growth that search provides.
Approach JavaScript with curiosity and appreciation and JavaScript will show you a whole new way of thinking about the world.
Those who do understand JavaScript's point of view are able to:
- write compact code that works in a wide variety of situations
- grasp the design approaches of new JavaScript frameworks (React, Vue, Angular)
- debug subtle, yet tricky bugs
These are all abilities worth having! So, let's get to know the mind of JavaScript by learning some of the amazingly cool things we can do with functions.
First, we'll start off by doing a quick recap of the basic use and creation of functions. Make sure that you're comfortable with these declarations and concepts as they're going to be the essential tools you need to understand JavaScript's love of the function.
Then we'll take a slight tangent: we're going to explore JavaScript's
collection-processing methods. These are methods with names like map
,
reduce
, and filter
. If you come from a Ruby background you'll recognize
these as the Enumerable
methods and will be comfortable with the idea
of what they do and how they work. But, importantly, these methods, in
JavaScript work by doing some really surprising stuff with functions. So
while we want you to know these methods for their own sake — they'll
make doing data processing much easier — we also want you to see
how these methods show JavaScript's love of passing functions about.
With a good grip of functions, we'll tackle one of the biggest mysteries
of learning JavaScript, the keyword this
and its associated methods
of call
, bind
, and apply
. These methods consistently baffle new
JavaScript developers and yet they are absolutely essential to working
with JavaScript frameworks like React and Angular and writing Object-
Oriented JavaScript. Many developers never really appreciate what's happening
here and are forever searching the internet or avoiding code that makes
them uncomfortable. We won't let that happen to you. Oh yeah, interviewers
love to ask questions in this area, so we want to make sure you're
well-prepared!
After that, you might fall in love with functions as much as JavaScript has. You're going to see the wisdom of some of JavaScript's choices and are going to be a more-thoughtful, more-empathetic, and more robust developer.