Video Lesson

Lesson Notes

Introduction to Arrow Functions in JavaScript

Arrow functions provide a concise syntax for writing functions and also capture this lexically.

Basic Arrow Function Syntax

1// Regular anonymous function 2const myFn = function() { 3 console.log("Hello world"); 4}; 5 6// Arrow function equivalent 7const myArrowFn = () => { 8 console.log("Hello world"); 9};

Even Shorter Syntax

  • If the function body is a single expression, you can omit the braces and return keyword:
1const greet = () => console.log("Hello from Arrow");

Parameters and Implicit Return

  • With parameters, list them in parentheses before the =>.
  • For a single expression, the result is returned automatically.
1// Two-parameter arrow function with implicit return 2const add = (x, y) => x + y; 3 4// Usage 5console.log(add(3, 4)); // 7

Key Points

  • No function keyword required.
  • Implicit return when omitting braces {}.
  • Arrow functions do not have their own this (they inherit it lexically).

Use arrow functions for shorter, more readable callbacks and one-off functions.

AI Assistant

Sign In Required

Sign in and subscribe to use the AI assistant for instant help with your lessons.

Sign In

Arrow functions

In this lesson, you'll discover the power of arrow functions in JavaScript, learning how to write concise, readable code while effectively capturing `this` lexically. Master the syntax and benefits of arrow functions to enhance your coding efficiency and streamline your function definitions.

2m 30s

Course Content

0 of 32 lessons completed
6. Promises, Async and Await
0 of 0 completed
7. The DOM
0 of 0 completed