6.2 Arrow Method

The arrow method is added to JavaScript in ES6 (Think different versions of JavaScript). It has some benefits. One of which is that it is shorter than your typical method.

// typical method
function powerTwo(num) { return num * num; }

// arrow method
let powerTwo = (num) => num * num;

Structure

const let methodName = (Parameter1, Parameter2, ...) => { /* */ };
// note: if you don't use brackets, it is implied that whatever comes after the 
// arrow is something you want to return.

There are some downsides to arrow methods:

  1. They are anonymous.
  2. No self-referencing

Practice

You can add practice problems here if you want. Follow the format below.

💻 Template code

✅ Solution code

Previous Section

6.1 What Are Methods?

Next Section

6.3 Difference Between Arrow and Regular Method

<aside> ⚖️ Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License.

If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact [email protected] for inquiries.

</aside>