Session Plan

Session Materials

These are some examples of previously created materials by mentors that you can use yourself, or for inspiration:

  • Demo – In-session code: index.js (worksheet with Task/Next comments to implement this session plan) and index-solution.js.

  • Event loop demo – Draggable code blocks (sync, setTimeout) into Call stack, Timer, Async queue. Use it to explain how the event loop works under the hood.

Session Outline

  1. Functions – passing a function as an argument

    • Repeat everything about functions. Functions as a variable: pass as argument, call from inside another function.

    • This is super good at explaining function logic: Function graphic.

    • Demo: implement functionRunner.

  2. Callbacks – setTimeout and the event loop

    • Explain how setTimeout(callback, delay) works, why the timer is never exact and why a 0 delay doesn't make it a sync operation.

    • Event loop demo can help with explaining how async operations work under the hood.

    • Solve console-order.md together with the trainees.

  3. (Optional) Infinite loop – sync vs async

    • Implementation of an infinite loop with both sync and async operations and demonstrating whether it freezes the page or not. Helps to realise how async operations work under the hood.

  4. Callbacks – events (addEventListener)

Also hammer in the point of the difference between:

Here's a good practical example of callbacks (TODO: move this to this repo).

Code inspiration

Calling a function within a function

Callback functions

Event Listeners

Anonymous vs named function

Exercises

See Exercises. Trainees show results on the page (update the DOM), not in the console.

Last updated