Stage 1 · Lesson 2 of 9
Functions, closures and this
In , functions are values, and code passes them everywhere: onPress handlers, for array methods and . Learn function declarations and arrow functions, plus default and rest parameters. Then learn : a function keeps access to the variables from where it was created.
Closures explain the most common React bug, the stale closure. That is when a handler or effect still sees a value from an earlier render. Learn how this works too.
A regular function gets this from how it is called, while an arrow function takes it from the code around it. Modern React code uses functions and hooks rather than classes, so this matters less than it once did.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking JavaScript Fundamentals
Design Gurus · Beginner · $50
Beginner JavaScript with an exercise after most lessons
- GuideFreeJavaScript.info
Ilya Kantor
Free and thorough: Part 1 is the language, skip the browser chapters in Part 2