JS Learning

JavaScript Functions

Lesson Progress0%

Section 3 of 4

Arrow Functions

Arrow Functions

Topic Overview

Take your time to understand each concept. Practice with the examples below!
Arrow functions are the modern, streamlined way to write functions. They're called "arrow" functions because they use => which looks like an arrow!

Basic syntax:

const functionName = (parameters) => {
// Instructions
};

The magic of arrow functions:

  • Shorter and cleaner to write
  • Perfect for simple operations
  • Can be even shorter for one-line functions

Three ways to write them:

1. Full syntax (multiple lines):
const add = (a, b) => {
const sum = a + b;
return sum;
};
2. Shorter (one expression):
const add = (a, b) => {
return a + b;
};
3. Shortest (implicit return):
const add = (a, b) => a + b;

When to use arrow functions:

  • For simple calculations
  • When passing functions as arguments
  • In modern JavaScript code
  • When you want cleaner, more readable code

One limitation: Arrow functions can't be used with 'new' keyword (don't worry about this for now!)

Ready to practice? Try the exercise below to reinforce your learning!

Try it yourself

Convert this regular function to an arrow function: function add(a, b) { return a + b; }

Loading...