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

    Errors and async · Lesson 38 of 45

    Fetching data from an API

    Talk to a server and show the data it sends.

    9 minutes2 games

    An API is a server address that returns data (usually JSON). fetch(url) sends a request and returns a promise of a response. Check response.ok, then read the body with await response.json().

    Browser: fetch(url)

    HTTP request (GET)

    Server replies: status + JSON

    await res.json() → object

    JavaScript
    async function loadTodo(id) {
      try {
        const res = await fetch(`https://jsonplaceholder.typicode.com/todos/${id}`)
        if (!res.ok) throw new Error("HTTP " + res.status)
        const todo = await res.json()
        console.log(`#${todo.id}: ${todo.title}`)
        console.log("done?", todo.completed)
      } catch (err) {
        console.log("Could not load:", err.message)
      }
    }
    loadTodo(1)

    This is a real free test API. Change the id and run again.

    Sending data (POST)

    JavaScript
    const res = await fetch("https://jsonplaceholder.typicode.com/posts", {
      method: "POST",
      headers: { "Content-Type": "application/json" },
      body: JSON.stringify({ title: "Hello", body: "From SeaCode", userId: 1 }),
    })
    const created = await res.json()
    console.log(res.status, "created post with id", created.id)
    StatusMeaning

    200 / 201

    OK / created

    400

    bad request

    401 / 403

    not signed in / not allowed

    404

    not found

    500

    server error

    Important

    fetch doesn't treat 404 or 500 as errors! It only rejects if the network itself fails, so always check res.ok yourself.

    Interview question

    What is CORS?

    Order the lines

    Order the steps to fetch data correctly.

    1. Click the lines in the right order

    Quick question

    The server replies 404. What does fetch do?

    Learn more from

    • javascript.info: Fetchjavascript.info
    • MDN: Using the Fetch APIdeveloper.mozilla.org
    • MDN: HTTP response status codesdeveloper.mozilla.org
    • MDN: CORSdeveloper.mozilla.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    Previousasync and awaitNextSearching with regular expressions
    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.