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

    Practical tools and techniques · Lesson 41 of 45

    Testing and debugging JavaScript

    Boundary cases, clear functions and result checking.

    8 minutes1 games

    Test expected behavior for known inputs, not only the absence of errors. A pure function returns a result from its inputs without changing external state, making testing easier. When debugging, reduce the example and inspect values with debugger or breakpoints.

    JavaScript
    function grade(score) {
      return score >= 60 ? "Pass" : "Retry"
    }
    const cases = [[59, "Retry"], [60, "Pass"], [100, "Pass"]]
    for (const [input, expected] of cases) {
      const actual = grade(input)
      if (actual !== expected) throw new Error(`Failed at ${input}`)
    }
    console.log("3 checks passed")
    ToolUse

    59

    Below boundary

    60

    At boundary

    100

    Higher case

    Important

    Do not use === to compare object contents; it compares identity. Check relevant fields or use your project’s deep-equality test tools.

    Interview question

    Why is testing 60 important here?

    Exercise

    Write clampScore(n) limiting a number to 0–100. Print results for -5, 60 and 120.

    Expected output:
    0
    60
    100
    JavaScript

    Learn more from

    • javascript.info: testing-mochajavascript.info
    • MDN: further readingdeveloper.mozilla.org

    Played 0 of 1 games

    Sign in to save your progress and earn XP.

    PreviousCancellation and stale resultsNextMap and Set
    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.