JavaScript
The event loop, closures, this and the rest of the runtime rules.
The course
Open the courseStart at 01. The first lesson names the types. The next one builds an object. Each sample is on the page.
-
Skill
Basics
The types, explained, then an object you can name and call.
-
01
JavaScript from zero: a value has a type
Start here
typeof reports the type of a value. A latte label uses a number, a string, and a boolean. The program prints latte $4.50 ready, then number string boolean.
Adds The types this course uses
-
02
JavaScript from zero: an object has fields
An object groups named fields. A latte has a name and a price in cents. The program prints latte $4.50.
Adds An object you can name and call
-
01
JavaScript from zero: a value has a type
Start here
-
Practice
Tips
A rule that prevents a bug, then a program that uses the object.
-
03
JavaScript from zero: a class holds the method
A class puts the fields and the method on one object. new Item makes a latte. label prints latte $4.50.
Adds A tip that prevents a bug
-
04
JavaScript from zero: const does not freeze the fields
const stops a new assignment to the name. It does not freeze the fields. A spread copies the drink. The original stays 450. The tipped copy is 540.
Adds A program that uses the object
-
03
JavaScript from zero: a class holds the method
-
Further
A whole program
One more idea, then a program that puts the pieces together.
-
05
JavaScript from zero: a method needs its object
Pulling a method off the object and calling it loses this. The detached call throws. Calling label on the latte prints latte $4.50.
Adds A program that puts the pieces together
-
06
JavaScript from zero: pass the object
A function can take the object and read the fields it needs. price takes a drink and returns the label. The program prints latte $4.50.
Adds A program that puts the pieces together
-
05
JavaScript from zero: a method needs its object
GoByte Skills: JavaScript track, 3 lessons. The event loop, closures and this: the runtime rules behind JavaScript's surprises.
Open the JavaScript trackArticles
RSS-
this: decided at the call site
GoByte Skills #18: this is decided at the call site, not where the function is written. One function, three calls, three answers, and why arrows opt out.
-
Closures: functions remember where they were born
GoByte Skills #17: A closure captures the variable, not the value. That is why three callbacks in a var loop all print 3 and the let loop prints 0, 1, 2.
-
The event loop: await does not block
GoByte Skills #16: await suspends one function, not the thread. Six log lines, two queues, one fixed order, and why a setTimeout of 0 still waits for every microtask.