Chapter 10: Arrow functions and scope
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
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
- Declare an arrow function
- Call it
- Try using a block-local variable outside its block
Example
const double = n => n * 2;
console.log(double(7));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
60-chapter learning path
Start at chapter 1, or choose any topic. Your progress is tracked separately for each chapter.
JavaScript fundamentals
TypeScript fundamentals
Playwright • setup & locators
Playwright • interactions & assertions
Playwright • framework & debugging
Playwright • real-world automation
Interactive practice lab
Try the controls below and observe the corresponding Playwright locator instructions. This browser demo does not execute Node.js or Playwright Test; copy the code to your local Playwright project to automate it.
Task manager demo
Suggested automation
Actions on the demo update these examples. In your local test use a page that contains the same controls.
Download a standalone lab page, then serve it locally (for example with Python's http.server). Navigate to it in a Playwright test.