ESSENTIALS
BUILDING
BLOCKS AND
FUNCTIONS
, WHAT ALL I HAVE COVERED
Program Structure
1. Expressions
2. Statements
3. Side Effects
4. Semicolons
5. Bindings (Variables)
6. Binding Names
7. The Environment
8. Functions
9. Growing Functions
10. Functions and Side Effects
11. The console.log Function
12. Return Values
13. Control Flow
14. Conditional Execution
15. Loops (While, Do-While, and For)
16. Indenting Code
17. Breaking and Continuing in Loops
18. Updating Bindings Succinctly
19. Switch Statement
20. Capitalization in JavaScript
Functions
1. Defining a Function
2. Bindings and Scopes
3. Functions as Values
4. Declaration Notation
5. Arrow Functions
6. The Call Stack
7. Optional Arguments
8. Closure
9. Recursion
10. Growing Functions
11. Functions and Side Effects
,
, PROGRAM STRUCTURE
1. Expressions
An expression is a piece of code that produces a value. Think of an expression like a
phrase in a language that communicates an idea. In JavaScript, expressions can be
simple or complex. Here are some examples:
- A simple expression:
5
This is just a number, and its value is obviously `5`.
- A slightly more complex expression:
5 + 10
This adds two numbers together and produces the value `15`.
Expressions can be compared to a basic mathematical calculation, like doing sums in
your head. Each expression leads to a result (a value).
Key Idea: If you can imagine something that gives you a specific value (like calculating
a total), that’s an expression!
Nested Expressions (Expressions inside Expressions)
Just like how a sentence in English can have sub-sentences, expressions can contain
other expressions. For example:
(5 + 10) * 2
Here, `(5 + 10)` is a sub-expression, which evaluates to `15`. Then, `15 * 2` gives us
the final result of `30`.
In a way, expressions can be like building blocks. You can piece them together to
form more complex expressions, and each one will still evaluate to a value.