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

    JavaScript in the page · Lesson 30 of 45

    Creating elements

    Build part of the page with code, from data.

    8 minutes2 games

    document.createElement("li") creates a new element in memory; parent.append(el) puts it on the page; el.remove() takes it away. This is how any list is built from data: products, messages, comments.

    HTML
    <ul id="list"></ul>
    <button id="add">Add course</button>
    
    <script>
      const courses = ["HTML", "CSS", "JavaScript"]
      const list = document.querySelector("#list")
    
      function render() {
        list.replaceChildren()
        for (const name of courses) {
          const li = document.createElement("li")
          li.textContent = name
          const del = document.createElement("button")
          del.textContent = "✕"
          del.onclick = () => {
            courses.splice(courses.indexOf(name), 1)
            render()
          }
          li.append(" ", del)
          list.append(li)
        }
      }
    
      document.querySelector("#add").onclick = () => {
        courses.push("Course " + (courses.length + 1))
        render()
      }
      render()
    </script>

    Click “Add course” and ✕. The idea: data lives in an array, and render redraws it each time.

    Important

    This idea (data → a function that draws the page) is exactly React's idea: you change the data, and React redraws the difference for you.

    Interview question

    Why can adding 1000 elements one at a time be slow, and what's the fix?

    Order the lines

    Order the lines to add a new item to the list.

    1. Click the lines in the right order

    Quick question

    Which line removes el from the page?

    Learn more from

    • javascript.info: Modifying the documentjavascript.info
    • MDN: Document.createElement()developer.mozilla.org

    Played 0 of 2 games

    Sign in to save your progress and earn XP.

    PreviousControlling the page (DOM)NextEvents
    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.