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 9 of 60~12 min • Beginner
Chapter 09JavaScript

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

  1. Define a function
  2. Pass arguments
  3. Inspect the returned value

Example

JavaScript
function total(price, quantity) {
  return price * quantity;
}
console.log(total(25, 4));
Expected result: 100
💡 Point to remember
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