Checkpoint: Data & Logic

You've learned iterators, generators, strings, numbers, loops, conditionals and type coercion — let's combine them. Up to now each topic stood on its own. Real programs blend them: you loop over rows of text, slice and trim each field, convert strings to numbers, and branch on conditions to summarize the result.

Learn Checkpoint: Data & Logic in our free JavaScript course — a beginner-friendly interactive lesson with runnable examples, a practice exercise and a quick…

Part of the free JavaScript course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.

In this checkpoint you'll build a small data-summarizer from scratch, then test your understanding with a quiz. No new syntax — just everything you already know, working together.

This checkpoint draws on the last seven lessons. Here's the toolkit you're about to use all at once:

Before the big build, here's a tiny preview that touches every tool you'll need. Read it and predict the output — it's the whole checkpoint in eight lines:

That's the pattern — split, clean, convert, decide, report. Now scale it up to many rows.

You're given a multi-line string of CSV-ish sales data. Each line is product,quantity,price . The data is messy — there's a header row, some stray spaces, and one blank line. Your job is to parse and summarize it.

Start from the scaffold below. Try it yourself first, then reveal the solution to compare.

Here's one clean way to do it. Notice how each step maps to a skill from the recap card:

Why it works: splitting on "\n" then filtering empties handles the blank line; map(f => f.trim()) cleans every field at once; Number() quietly trims and converts the digits; the Number.isNaN guard protects against malformed rows; and a single running bestQty comparison finds the top seller in one pass. That's all seven prior lessons cooperating in about twenty lines.

Answer each in your head first, then reveal to check. These pull directly from the last seven lessons.

1. What does "a,b,,c".split(",").length return?

4 . Splitting on "," keeps the empty field between the two commas, producing ["a", "b", "", "c"] — four elements. This is why real parsers must decide whether to keep or drop empty fields.

2. What is the value of Number(" 7 ") and Number("7px") ?

7 and NaN . Number trims surrounding whitespace, so " 7 " becomes 7 . But it requires the whole string to be numeric, so "7px" fails and yields NaN . Use parseInt if you expect trailing units.

3. In the build, why do we use continue for the header instead of break ?

continue skips only the header line and keeps processing the rest. break would exit the loop entirely, so no data rows would ever be summarized. continue = skip one; break = stop all.

34 . Multiplication runs first ( 2 * 2 = 4 ), then "3" + 4 concatenates because one operand is a string, giving "34" . Operator precedence and coercion together.

5. Which fallback keeps a valid 0 price: price || 9.99 or price ?? 9.99 ?

price ?? 9.99 . ?? only falls back on null / undefined , so a free item priced at 0 survives. || would treat the falsy 0 as missing and wrongly replace it with 9.99 .

6. Why does (0.1 + 0.2).toFixed(2) give "0.30" while 0.1 + 0.2 === 0.3 is false ?

Floating-point can't store 0.1 and 0.2 exactly, so the sum is 0.30000000000000004 , which is not strictly equal to 0.3 . toFixed(2) rounds for display and returns the string "0.30" . For money, work in integer cents.

If the build clicked, you have a solid command of JavaScript's core data and logic. Up next: Recursion & the Call Stack — functions that call themselves! 🌀

Practice quiz

What does "a,b,,c".split(",").length return?

  • 3
  • 5
  • 4
  • It throws

Answer: 4. Splitting keeps the empty field between the two commas: ["a", "b", "", "c"] has 4 elements.

What is the value of Number(" 7 ")?

  • 7
  • NaN
  • " 7 "
  • undefined

Answer: 7. Number trims surrounding whitespace, so a clean numeric string converts to 7.

What does Number("7px") evaluate to?

  • 7
  • "7px"
  • 0
  • NaN

Answer: NaN. Number requires the whole string to be numeric; trailing letters make it NaN. Use parseInt for units.

In a loop, what is the difference between continue and break?

  • continue stops the loop; break skips one
  • continue skips the current iteration; break exits the loop
  • They are identical
  • continue only works in for-of

Answer: continue skips the current iteration; break exits the loop. continue skips just the current iteration; break exits the whole loop.

What does console.log("3" + 2 * 2) print?

  • 34
  • 10
  • 7
  • NaN

Answer: 34. Multiplication runs first (4), then "3" + 4 concatenates to "34" because one operand is a string.

Which fallback keeps a valid 0 price instead of replacing it?

  • price || 9.99
  • Both keep it
  • price ?? 9.99
  • Neither keeps it

Answer: price ?? 9.99. ?? only falls back on null/undefined, so a real 0 survives; || treats falsy 0 as missing.

Is 0.1 + 0.2 === 0.3 true or false in JavaScript?

  • true
  • false
  • It throws
  • Depends on the engine

Answer: false. Floating-point can't store 0.1 and 0.2 exactly; the sum is 0.30000000000000004, not 0.3.

What does (0.1 + 0.2).toFixed(2) return?

  • the number 0.3
  • "0.300000"
  • 0.30000000000000004
  • "0.30"

Answer: "0.30". toFixed rounds for display and returns a string, so you get the string "0.30".

What does parseInt("7px") return?

  • NaN
  • 7
  • "7"
  • 0

Answer: 7. Unlike Number, parseInt reads leading digits and stops at the first non-numeric character, giving 7.

What is the result of "5" === 5?

  • true
  • It coerces to true
  • false
  • It throws

Answer: false. === compares without coercion; a string and a number of different types are never strictly equal.