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 16 of 45

    Parameters: default, rest and spread

    Default values, any number of inputs, and spreading arrays.

    7 minutes3 games
    • default: function greet(name = "friend") uses the default when no value is passed.
    • rest ...args in the definition collects extra arguments into an array.
    • spread ...arr in a call unpacks an array into separate values.
    JavaScript
    function greet(name = "friend") {
      return `Hello, ${name}!`
    }
    console.log(greet())
    console.log(greet("Hana"))
    
    function sum(...nums) {
      let total = 0
      for (const n of nums) total += n
      return total
    }
    console.log(sum(1, 2, 3, 4))
    
    const scores = [70, 95, 88]
    console.log(Math.max(...scores))
    console.log([...scores, 100])

    [70, 95, 88]

    ...scores

    Math.max(70, 95, 88)

    Spread unpacks the array into separate values.

    Important

    The rest parameter must come last: function f(a, ...rest) works; function f(...rest, a) doesn't.

    Interview question

    How do you copy an array or object without changing the original?

    What's the output?

    function f(a, b = 10) {
      return a + b
    }
    console.log(f(5))
    console.log(f(5, 1))

    What will this code print?

    Complete the code

    Collect every argument into an array called items.

    function list(items) {
      return items.length
    }

    Exercise

    Write average(...nums) returning the mean, then print average(10, 20, 30) (20).

    Expected output: 20

    JavaScript

    Learn more from

    • javascript.info: Rest parameters and spread syntaxjavascript.info
    • MDN: Default parametersdeveloper.mozilla.org
    • MDN: Spread syntaxdeveloper.mozilla.org

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousArrow functionsNextScope and closures
    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.