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

    Functions

    Write code once, use it many times.

    9 minutes3 games

    A function is named code that takes inputs (parameters) and can give back a result with return. The values you pass when calling it are arguments. A function exits as soon as it reaches return.

    Step by step1 / 5
    1. ▶function area(width, height) {
    2. 2 return width * height
    3. 3}
    4. 4const a = area(4, 5)
    5. 5console.log(a)

    Variables

    —

    Output

    …

    This only defines the function; nothing runs yet.

    console.log inside a function only prints. return hands back a result you can use elsewhere.

    Important

    A function without return gives back undefined. A good function does one thing and is named with a verb: calculateTotal, formatDate, isValidEmail.

    Interview question

    What's the difference between a function declaration and a function expression?

    What's the output?

    function double(n) {
      return n * 2
      console.log("done")
    }
    console.log(double(4))

    What will this code print?

    Complete the code

    Complete the function that returns the bigger of two numbers.

    function max(a, b) {
      if (a > b) {
         a
      }
      return 
    }

    Exercise

    Write greet(name) that returns Welcome, <name>!, then print greet("Ali").

    Expected output: Welcome, Ali!

    JavaScript
    function greet(name) {
      
    }
    

    Learn more from

    • javascript.info: Functionsjavascript.info
    • javascript.info: Function expressionsjavascript.info
    • MDN: Functionsdeveloper.mozilla.org

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousChallenge: FizzBuzzNextArrow functions
    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.