Join Eve Porcello for an in-depth discussion in this video Arrow functions, part of Up and Running with ECMAScript 6.
- Arrow functions, sometimes called fat arrow functions, have an abbreviated syntax for working with functions. We're dealing with a new token here. The equal sign and the greater than symbol. Don't get this confused with comparison operators, because it does something quite different. Let's create a function called student list. Our student list function is going to be a traditional function and then we're going to update it as an arrow function. So the function will take in students.
It will then console log the students. I also want to call this function here, and I will pass in an array of student names. Joe, Cindy, and Jeanne. Great, so this is where the arrow function comes in. It provides us with some syntactic sugar so we can shorten this quite a bit. The first thing that we'll do here is we'll remove the function keyword.
I then am going to remove the curly braces. I'm also going to move this console log message here to line seven. Finally, we need to add our arrow function so we'll do that right here. So look how much shorter this is. And then when I run this, we see Joe, Cindy, and Jeanne being logged to our console. Let's take a lot at this again. And since I am only passing in one argument, I can even remove these parenthesis here.
- What is ECMAScript?
- Transpiling ECMAScript with Babel and Babel-node
- Using the let and const keywords
- Creating strings with template strings
- Enhancing object literals
- Working with ES6 classes and class inheritance
Skill Level Beginner
Q: The Babel API is out of date. How do I proceed with the course?
A: We are updating the course. In the meantime, you can install the babel-cli package and then install the presets that you need to follow along with the tutorials.