Add lesson 1: Values, variables and const
3 changed files with 35 additions and 0 deletions
lessons/01-values-variables-and-const/README.md ADDED
| @@ -0,0 +1,19 @@ | ||
| 1 | +# Lesson 1: Values, variables and const | |
| 2 | + | |
| 3 | +We look at values, variables and const the way working developers use it, with examples you can change and run right away. | |
| 4 | + | |
| 5 | +Full lesson: [https://glibcode.net/courses/javascript-web/lessons/1](https://glibcode.net/courses/javascript-web/lessons/1) | |
| 6 | + | |
| 7 | +## Files | |
| 8 | + | |
| 9 | +- `values.js`: let, const and the basic types | |
| 10 | + | |
| 11 | +## Run it | |
| 12 | + | |
| 13 | +```sh | |
| 14 | +node values.js | |
| 15 | +``` | |
| 16 | + | |
| 17 | +## Exercises | |
| 18 | + | |
| 19 | +See [exercises.md](exercises.md). Ask in the forum once you've tried. | |
lessons/01-values-variables-and-const/exercises.md ADDED
| @@ -0,0 +1,5 @@ | ||
| 1 | +# Exercises: lesson 1 | |
| 2 | + | |
| 3 | +1. Break the example on purpose: delete a bracket or misspell a name. Read the error message. Which line does it point to? | |
| 4 | +2. What happens with an empty input? Change the code so it handles that case with a clear message. | |
| 5 | +3. Time yourself: rewrite the example from memory in 10 minutes, then diff it against the original. | |
lessons/01-values-variables-and-const/values.js ADDED
| @@ -0,0 +1,11 @@ | ||
| 1 | +const name = "Ada"; | |
| 2 | +let visits = 0; | |
| 3 | +visits += 1; | |
| 4 | + | |
| 5 | +console.log(typeof name, typeof visits, typeof true, typeof undefined); | |
| 6 | +console.log(`${name} visited ${visits} time${visits === 1 ? "" : "s"}`); | |
| 7 | + | |
| 8 | +// const stops re-assignment, not changes inside objects | |
| 9 | +const user = { name }; | |
| 10 | +user.name = "Grace"; | |
| 11 | +console.log(user); | |