Skip to content
    SeaCode
    Learning tracksCode ArenaWorkshops & EventsInstructors
    Log inSign up
    JSJavaScript

    Getting started

    • What is JavaScript?
    • Variables: let, const and var
    • Data types
    • Type conversion

    Operators and strings

    • Arithmetic and assignment
    • Comparison and logic
    • Strings and template literals
    • String methods
    • Numbers and Math

    Control flow

    • Conditions: if and else
    • switch and the ternary operator
    • Loops: for and while
    • Challenge: FizzBuzz

    Functions

    • Functions
    • Arrow functions
    • Parameters: default, rest and spread
    • Scope and closures
    • Callbacks and higher-order functions

    Arrays

    • Array basics
    • map, filter and find
    • reduce and sorting
    • Destructuring

    Objects

    • Object basics
    • Copies and references
    • Methods and this
    • JSON and optional chaining

    Classes and OOP

    • Classes
    • Inheritance

    JavaScript in the page

    • Controlling the page (DOM)
    • Creating elements
    • Events
    • Forms and validation
    • Saving in the browser (localStorage)

    Errors and async

    • Handling errors: try and catch
    • Timers and the event loop
    • Promises
    • async and await
    • Fetching data from an API

    Practical tools and techniques

    • Searching with regular expressions
    • Cancellation and stale results
    • Testing and debugging JavaScript

    Modern JavaScript and a project

    • Map and Set
    • Dates and localised formatting
    • Modules: import and export
    • Project: a complete to-do app
    JavaScript

    Functions · Lesson 18 of 45

    Callbacks and higher-order functions

    Functions that take functions: the basis of map, filter and events.

    8 minutes3 games

    In JavaScript functions are values like numbers and strings: store them, pass them to other functions, return them. A function handed to another function to call later is a callback; the function that takes it is a higher-order function.

    JavaScript
    function repeat(times, action) {
      for (let i = 1; i <= times; i++) action(i)
    }
    
    repeat(3, (n) => console.log("Hello", n))
    
    const shout = (text) => text.toUpperCase() + "!"
    const whisper = (text) => text.toLowerCase() + "…"
    function say(text, style) {
      return style(text)
    }
    console.log(say("Hi", shout))
    console.log(say("Hi", whisper))

    You pass action

    repeat calls it 3 times

    each time with its number

    Important

    Pass the function itself, not its result: repeat(3, greet) is right; repeat(3, greet()) calls greet immediately and passes what it returned.

    Interview question

    What is “callback hell” and how do you avoid it?

    What's the output?

    function apply(x, fn) {
      return fn(x)
    }
    console.log(apply(4, (n) => n + 1))

    What will this code print?

    Spot the bug

    greet should be called 3 times. Which line has the mistake?

    Exercise

    Write applyTwice(fn, x) that returns fn(fn(x)). Print applyTwice((n) => n * 3, 2) (18).

    Expected output: 18

    JavaScript

    Learn more from

    • MDN: Callback functiondeveloper.mozilla.org
    • javascript.info: Introduction: callbacksjavascript.info
    • Eloquent JavaScript: Higher-Order Functionseloquentjavascript.net

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousScope and closuresNextArray basics
    SeaCode

    Learn to code for real, online or at our branch in front of Cairo University, Giza.

    Learn

    • All courses
    • Interactive tutorials
    • Interview practice problems
    • Mock interview
    • Learning tracks
    • Code Arena
    • Workshops & Events
    • Knowledge library
    • Team projects

    Your account

    • Log in
    • Sign up
    • Learning plan
    • Certificates
    • Site map

    Contact us

    • WhatsApp
    • 010 9094 1104
    • In front of Cairo University, Giza

    © 2026 SeaCode. All rights reserved.