Skip to content

Commit efa24a9

Browse files
committed
feat: enhance README files with code comments and variable declaration context
- Add a section on code comments in the main README, explaining their purpose and usage in TypeScript. - Update the variables exercise README to clarify the differences between `var`, `let`, and `const`, emphasizing modern best practices. - Modify the problem file to improve clarity on uncommenting code for demonstration purposes.
1 parent fc6b644 commit efa24a9

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

exercises/02.variables/01.problem.let-and-const/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const laptopPrice = 999.99
2020
// 🐨 Try uncommenting the line below - what happens?
2121
// TAX_RATE = 0.10
2222

23-
// @ts-expect-error - 💣 remove this comment
24-
console.log('Cart subtotal:', cartTotal)
23+
// Uncomment the following lines to see the results
24+
// console.log('Cart subtotal:', cartTotal)
2525
// console.log('Tax:', cartTotal * TAX_RATE)
2626
// console.log('Final total:', finalTotal)

exercises/02.variables/README.mdx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,14 @@ arr.push(7) // Mutation - modifying the SAME array
4444
</callout-warning>
4545

4646
Understanding this distinction helps you write predictable, bug-free code.
47+
48+
<callout-info>
49+
You might encounter `var` in older JavaScript code. It's the original way to
50+
declare variables, but it has confusing scoping rules (function scope instead
51+
of block scope) and allows redeclaration. Modern JavaScript introduced `let`
52+
and `const` specifically to fix these issues. There's no reason to use `var`
53+
in new code, which is why we focus exclusively on `let` and `const`.
54+
</callout-info>
55+
56+
📜 For more details, see MDN's guide on [variable
57+
declarations](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#declarations).

exercises/README.mdx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,28 @@ By the end of this workshop, you'll be able to:
3636
- Understand how TypeScript helps catch errors before your code runs
3737

3838
Let's build something solid! 🏗️
39+
40+
<callout-info>
41+
**Code comments** are notes you write in your code that explain what it does.
42+
</callout-info>
43+
44+
Code comments start with `//` for single-line comments or `/* */` for multi-line
45+
comments. Comments are ignored by TypeScript—they're just for humans to read.
46+
You'll see comments throughout the exercises to help explain concepts. Feel
47+
free to add your own comments to help you understand the code! Here are some examples:
48+
49+
```ts
50+
// This is a single-line comment
51+
52+
/*
53+
This is a
54+
multi-line comment
55+
*/
56+
57+
/*
58+
* Sometimes you'll see multi-line comments
59+
* with a star at the beginning and end.
60+
* These extra stars are unnecessary, but
61+
* look nice so people use them.
62+
*/
63+
```

0 commit comments

Comments
 (0)