Lesson 14 — Variables & Types: The Named Boxes · Practical QA
LESSON VIEW
F-01 · BASIC · PRACTICAL QA

Lesson 14 — Variables & Types: The Named Boxes

Objective: Variables — the named boxes every test is built from. You will store a base URL, an expected price, and a booking count, and know exactly which box each belongs in. Every example is FreshNest test code — nothing here is abstract.

⏱ ≈5 min full lesson · Converted from the F-01 module deck · English edition — Español · العربية · বাংলা in translation

⚡ Key Points

  • const is sealed, let refills — A variable is a named box holding one value.
  • Your first variables — RUN IT, then change it: set expectedPrice to 170 and re-run — the assertion now describes the 3-bedroom Standard clean.
  • Three types run your tests — Every value has a type, and the type decides what you may do with it.
  • Inference vs annotation — TypeScript infers the type from the first value (beds is a number because 2 is).
  • The answer — It prints: Standard 170. Execution is top-to-bottom and a variable always holds its LATEST value when read.
  • Name the meaning — Names are documentation the compiler enforces.

📖 Read

In ~5 minutes: variables — the named boxes every test is built from. You will store a base URL, an expected price, and a booking count, and know exactly which box each belongs in. Every example is FreshNest test code — nothing here is abstract.

const is sealed, let refills: A variable is a named box holding one value. const means the box is sealed after you fill it — use it for anything that must not change mid-test (URLs, expected prices). let means the box can be refilled — use it for things that genuinely change (a counter, the current row). In test code, const is the default; let is the exception you can justify.

Your first variables: RUN IT, then change it: set expectedPrice to 170 and re-run — the assertion now describes the 3-bedroom Standard clean. Then add a last line that tries to reassign it — baseUrl = 'http://example.com' — and watch TypeScript refuse: const boxes do not refill. That refusal is a feature — it stops a test from quietly changing its own expectations halfway through. Code: const baseUrl = 'http://localhost:3000'; | let bookingCount = 0; | const expectedPrice = 210; // Deep clean, 2 bedrooms | bookingCount = bookingCount + 1; | console.log(baseUrl, expectedPrice, bookingCount);

Three types run your tests: Every value has a type, and the type decides what you may do with it. string is text ('$210'), number is arithmetic (210), boolean is true/false. The trap: the estimate on the page is TEXT — '$210' — while your expectation starts life as a NUMBER. Tests live exactly on that border, which is why this course writes expected prices as numbers in data and formats them at the assertion.

Inference vs annotation: TypeScript infers the type from the first value (beds is a number because 2 is). An annotation (: number) states it yourself — worth it for values a reader could misread, like a phone string that looks numeric but must never be added or divided. A phone number is a string that happens to contain digits; treat it as a number and the leading zero dies. Code: const beds = 2; // inferred: number | const label: string = 'Deep'; // annotated: string | const phone: string = '6095550142'; | const paid: boolean = true; | console.log(typeof beds, typeof label, typeof phone, typeof paid);

The answer: It prints: Standard 170. Execution is top-to-bottom and a variable always holds its LATEST value when read. The 140 existed only until line 2 replaced it. Hold onto that: half of all 'the test expected the wrong price' bugs are a box being read before — or after — the line that changed it.

Name the meaning: Names are documentation the compiler enforces. expectedDeepPrice tells the reader the value, the service, and its job; x or p2 tells nothing and will be misread at midnight. Rule of the framework: name a variable for what it MEANS in the booking world (beds, service, expectedPrice), never for its type or its position.

Fill the box: COMPLETE the line so the constant holds the Deep price for a 1-bedroom clean. FreshNest rules: Standard 2-bed is $140, each bedroom step is $30, Deep costs 1.5× Standard. (1-bed Standard = 140 − 30 = 110; Deep = 110 × 1.5.)

The answer: It refuses to compile — and that is the point. const turns a whole species of silent test corruption into a loud, immediate error. You have finished this module when: you can declare the base URL, an expected price, and a counter with the right keyword and type for each, and predict any of these snippets before running it.

Declare FreshNest's baseUrl, the $210 Deep 2-bed expectation, and a booking counter — right keyword, right type, meaningful names — and predict one snippet's output before running it.