JavaScript for QA Automation
MODULE 1 OF 10 β’ THEORY
1. Variables & Scope (let, const)
basicUse "const" for values that should not change after assignment (like timeouts, URLs, and element selectors). Use "let" for values that will be reassigned (like loop counters, toggle states, and retry accumulators). Avoid "var" because it is function-scoped and can cause leakages.
Syntax Template
const TIMEOUT = 5000; let retryCount = 0;
When to use
Always prefer const by default. Only use let when you explicitly plan to change the variable's value later in the test execution.
Best practice
Declare selectors and configuration objects with "const" to prevent accidental runtime reassignments that would break E2E test runs.
Node.js Console Output Simulator
v18.16.0[Node.js] Ready to execute js-variables.js...
[Node.js] Click "Run Code" to start execution.