TestingDocs.com logoTestingDocs.com
Automation learning lab
TestingDocs • Self-paced course

Playwright Automation
Self Study Guide

Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.

60 chaptersBeginner friendlyHands-on practice
JavaScript / Chapter 10 of 60~12 min • Beginner
Chapter 10JavaScript

Arrow functions and scope

Arrow functions provide concise function syntax and capture this from the surrounding scope. Variables declared with let or const are block scoped. A variable defined inside a function is not normally accessible outside it.

How it works

Step-by-step walkthrough

  1. Declare an arrow function
  2. Call it
  3. Try using a block-local variable outside its block

Example

JavaScript
const double = n => n * 2;
console.log(double(7));
Expected result: 14
💡 Point to remember
Do not assume arrow functions have their own this.

✎ Your practice task

Rewrite double as a traditional function.

Knowledge check

What does n => n * 2 return for 7?

🌐 Continue learning