Skip to content

Commit 073c1fe

Browse files
committed
Improve clarity and add helpful documentation
- Add floating point precision note to let/const exercise - Add MDN links for null and undefined - Add hint about nested loops for star staircase pattern - Add callout explaining callbacks and higher-order functions - Note that TypeScript provides type info, so JSDoc is for descriptions - Clarify never type exercise to explicitly mention using throwError function
1 parent 4f6c954 commit 073c1fe

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

exercises/02.variables/01.problem.let-and-const/README.mdx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,14 @@ const API_URL = 'https://api.example.com'
1919

2020
📜 [MDN - const](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/const)
2121

22+
<callout-info>
23+
You might notice JavaScript sometimes produces surprising decimal results like
24+
`0.1 + 0.2 = 0.30000000000000004`. This is due to how computers store decimal
25+
numbers in binary (floating point representation). It happens in most
26+
programming languages, not just JavaScript. For currency calculations in real
27+
apps, consider working in cents (integers) or using specialized libraries.
28+
</callout-info>
29+
30+
📜 [MDN - Number representation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number#number_encoding)
31+
2232
🐨 Once you've completed the exercise, run `node index.ts` in the playground to test your work!

exercises/03.primitive-types/03.problem.null-and-undefined/README.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ console.log(value !== undefined ? 'Has value: ' + value : 'No value')
3838

3939
📜 [TypeScript Handbook - Null and Undefined](https://www.typescriptlang.org/docs/handbook/2/narrowing.html#null-and-undefined)
4040

41+
📜 [MDN - null](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/null)
42+
43+
📜 [MDN - undefined](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined)
44+
4145
🐨 Once you've completed the exercise, run `node index.ts` in the playground to test your work!

exercises/04.control-flow/03.problem.loops/README.mdx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,20 @@ for (...) {
2626
}
2727
```
2828

29+
💰 You'll need **two loops** for this exercise—an outer loop for each row, and
30+
an inner loop to build the stars for that row. This is called a "nested loop":
31+
32+
```ts
33+
for (let row = 1; row <= 5; row++) {
34+
// inner loop builds stars for this row
35+
for (let star = 0; star < row; star++) {
36+
// add a star
37+
}
38+
}
39+
```
40+
2941
📜 [MDN - for statement](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for)
3042

43+
📜 [MDN - for...of](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...of) (an alternative loop syntax you'll see in the wild)
44+
3145
🐨 Once you've completed the exercise, run `node index.ts` in the playground to test your work!

exercises/05.functions/04.problem.arrow-functions/README.mdx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ function applyToNumber(
5252
const result = applyToNumber(5, (n) => n + 1) // 6
5353
```
5454

55+
<callout-info>
56+
A **callback** is a function you pass to another function to be called later.
57+
In the example above, `(n) => n + 1` is a callback—we're passing it to
58+
`applyToNumber`, which calls it with the value `5`. Functions that accept
59+
other functions as arguments are called **higher-order functions**. You'll use
60+
this pattern a lot with array methods like `map`, `filter`, and `reduce`.
61+
</callout-info>
62+
5563
📜 [Function Forms](https://kentcdodds.com/blog/function-forms)
5664

5765
🐨 Once you've completed the exercise, run `node index.ts` in the playground to test your work!

exercises/05.functions/05.problem.jsdoc/README.mdx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ function calculateArea(width: number, height: number): number {
2525
When you hover over `calculateArea` anywhere in your codebase, you'll see this
2626
documentation!
2727

28+
<callout-info>
29+
Since TypeScript already provides type information (parameter types, return
30+
types), JSDoc is primarily useful for **descriptions** and **examples** in
31+
TypeScript projects. The `@param` and `@returns` tags add human-readable
32+
explanations that go beyond what types alone can convey.
33+
</callout-info>
34+
2835
## Common JSDoc Tags
2936

3037
| Tag | Purpose |

exercises/06.void-and-never/02.problem.never-type/README.mdx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,17 @@ is one that always throws or exits early.
1515
🐨 Open <InlineFile file="index.ts" /> and:
1616

1717
1. Create a `throwError` function that throws and returns `never`
18-
2. Create a `parseNumber` function that converts a string to a number
19-
3. Create an `ensurePositive` function that throws if the number is negative
18+
2. Create a `parseNumber` function that converts a string to a number, using
19+
`throwError("Invalid number")` if the input can't be parsed
20+
3. Create an `ensurePositive` function that returns the number if positive, or
21+
uses `throwError("Number must be positive")` if negative
22+
23+
<callout-info>
24+
The key learning here is that `parseNumber` and `ensurePositive` should
25+
**use** the `throwError` function rather than throwing directly. This
26+
demonstrates how TypeScript's flow analysis understands that code after a
27+
`never`-returning function call is unreachable.
28+
</callout-info>
2029

2130
<callout-info>
2231
`Number(value)` converts a string to a number. If the string can't be parsed,

0 commit comments

Comments
 (0)