Playwright + TS · Lesson 1 of 36
Module 1: JavaScript Fundamentals
Your task
Complete the verification function:
const expectedTitle = "TargetQA - Learn Automation".if/else block to check if actualTitle === expectedTitle.isMatch = true; otherwise set isMatch = false.Write it in the editor, then press Check answer (Ctrl + Enter).
In this lesson
In modern JavaScript and TypeScript, we avoid var due to function-scoping and hoisting issues:
const: For values that never change (base URLs, test timeouts, page titles).let: For values that get reassigned (retry counters, iteration indices).const baseUrl = "https://targetqa.com";
let attemptCount = 0;
attemptCount++;string, number, boolean, null, undefined, symbol, bigint.undefined: A variable declared but not assigned a value.null: An intentional assignment representing "no object/value".=== (strict equality), !==, >, <, >=, <=.&& (AND), || (OR), ! (NOT).const status = isPassed ? "PASSED" : "FAILED";if (responseStatus === 200) {
console.log("Success");
} else if (responseStatus === 404) {
console.log("Not Found");
} else {
console.log("Unexpected status: " + responseStatus);
}// Standard for loop:
for (let i = 0; i < 3; i++) {
console.log("Retry attempt: " + i);
}
// for...of loop (iterates over values in array):
const tabs = ["Home", "Courses", "Practice"];
for (const tab of tabs) {
console.log("Checking tab: " + tab);
}
// for...in loop (iterates over object keys):
const testConfig = { browser: "chromium", headless: true };
for (const key in testConfig) {
console.log(key + ": " + testConfig[key]);
}Hello and welcome! In this lesson, we are starting with JavaScript fundamentals, focusing specifically on what you need for automation testing. When writing test scripts, you will constantly manage variables, evaluate conditions, and loop through page elements. We will cover const and let, primitive data types, conditionals, and loops so you can write clean, resilient test scripts. Let's get started!
Part of the Playwright + TS course (Playwright with TypeScript). Practice this concept live in the Playwright Online Compiler or explore our free automation practice form.
=== checks both value and type without type coercion. == converts types unexpectedly (for example, '0' == 0 is true, which causes silent automation bugs).
Use for...of to iterate through elements of arrays or lists of WebElements. Use for...in only when iterating through property names of an object.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___