Check out a free preview of the full Deep JavaScript Foundations, v3 course

The "Function Types Hierarchy" Lesson is part of the full, Deep JavaScript Foundations, v3 course featured in this preview video. Here's what you'd learn in this lesson:

Kyle presents a hierarchy of function types and explains each level based on information from previous lessons.

Preview
Close

Transcript from the "Function Types Hierarchy" Lesson

[00:00:00]
>> Kyle Simpson: So let's summarize our thoughts on, or my thoughts that I've shared with you, I guess I should say, on functions of their various different types. It is my opinion that function declarations have some superiority to them. We haven't even talked about all of those, we'll come back to those when we get to, for example, wasting, later.

[00:00:20]
But a function declaration has some benefits over a named function expression. But named function expressions have huge benefits over anonymous function expressions. So I feel much more strongly about the second two of these than the first two, even though I also do tend to prefer the named function declarations.

[00:00:41]
So it's just something to be aware of, because this isn't really something that can be such a hard and fast rule. You do have to look at the various different cases. And I certainly understand why people might use an arrow function when it's five characters doubling some variable.

[00:00:58]
But even in those cases where you're tempted just to save a little bit of time, I would still argue that the name, double it, tells me something more directly than looking at x times 2. So I just want you to consider that bigger purpose, which is we want to have our code communicate as effectively as possible, even at a glance, without somebody having to read and sort of mentally execute some code and figure out what it does, or consider any sort of corner cases on it.

[00:01:29]
We don't want the reader to have to do those things, ideally. We want them to be able to read our code and understand it's purpose almost at a glance. So those are the reasons why I prefer the functions in this order, and I would work my way down, and I would essentially only ever do the anonymous function expression in the arrow expression form.

[00:01:49]
And in that one particular case, I would only do so because I was getting lexical clicks, which we'll talk about later in the course.

Learn Straight from the Experts Who Shape the Modern Web

  • In-depth Courses
  • Industry Leading Experts
  • Learning Paths
  • Live Interactive Workshops
Get Unlimited Access Now