Functions, Parameters and Returns
- Functions. A function wraps steps behind a name so the same work runs anywhere with one call.
- Parameters and arguments. A parameter is the named slot in the definition; the argument is the actual value you pass in the call.
- Return values. The return statement hands one value back to the caller and stops the function immediately.
Scope, Closures and Lexical Environment
- Scope. A variable exists only inside its scope: the region of code, usually braces, allowed to see it.
- Closures. A function keeps using variables from where it was written even after that place has finished: that captured bundle is its closure.
- Lexical environment. Name lookup walks outward through the environments the source nesting created: this is lexical scoping, decided by where code is written.
Callbacks and Higher-Order Functions
- Functions as values. A JavaScript function is a value: it can sit in a variable, ride in an array, or be passed to another function.
- Callbacks. A callback is a function you hand to other code to run later: the pattern behind timers, events and array methods.
- Higher-order functions. A higher-order function takes or returns functions: map takes your transformer and applies it to every element.
Before and after this level
- Before: Level 2: Program Flow: Conditions and Boolean Logic, Loops and Iteration, Control Flow and Program Decisions.
- Next: Level 4: Arrays & Objects: Arrays and Collection Operations, Objects, Properties and Destructuring, Working With Nested Data.
In the app each of these ideas is taught and then asked back, and the level ends with a checkpoint and flashcards. See Checkpoints and flashcards.
Frequently asked questions
What does JavaScript Level 3: Functions & Scope cover?
Functions, Parameters and Returns, Scope, Closures and Lexical Environment, Callbacks and Higher-Order Functions: 3 lessons and 9 ideas.
What should I know before this level?
The level before it, Level 2: Program Flow, which covers Conditions and Boolean Logic, Loops and Iteration, Control Flow and Program Decisions.