2️⃣

6.2 Arrow Method

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.
    • If something breaks, you won’t be told where things went wrong.
  2. No self-referencing
    • If your method needs to refer to itself at some point (called Recursion), it’s not possible with arrow methods.

Practice

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

⚖️

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 classes@code4tomorrow.org for inquiries.