Chapter 09: Functions and parameters
Automation learning lab
Playwright Automation
Self Study Guide
Start from zero. Learn JavaScript and TypeScript, automate browsers, and build reliable end-to-end tests.
Functions and parameters
Functions group reusable behavior. Parameters accept inputs and return provides an output. A function can be called many times with different arguments. Small functions help tests avoid duplicated logic.
How it works
Step-by-step walkthrough
- Define a function
- Pass arguments
- Inspect the returned value
Example
function total(price, quantity) {
return price * quantity;
}
console.log(total(25, 4));Keep test helpers focused on a single responsibility.
✎ Your practice task
Add a function to calculate a discount.
Knowledge check
Which keyword sends a value back to the caller?
🌐 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.