1. JavaScript Fundamentals for Automation

Variables: var vs let vs const

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++;

Data Types in JavaScript

1. Primitives: string, number, boolean, null, undefined, symbol, bigint. 2. null vs undefined: - undefined: A variable declared but not assigned a value. - null: An intentional assignment representing "no object/value".

Operators & Conditionals

- Comparison: === (strict equality), !==, >, <, >=, <=. - Logical: && (AND), || (OR), ! (NOT). - Ternary: 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);
}

Loops for Automation

// 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]);
}

Task

  • Complete the verification function:
  • 1. Declare `const expectedTitle = "TargetQA - Learn Automation"`.
  • 2. Use an `if/else` block to check if `actualTitle === expectedTitle`.
  • 3. If true, set `isMatch = true`; otherwise set `isMatch = false`.
πŸ’‘Common doubts
Did you like the problem?
Lesson 1 of 36
TypeScript
Loading code editor…
Next