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

    Control flow · Lesson 10 of 45

    Conditions: if and else

    Let your code make decisions.

    8 minutes3 games

    if runs its block when the condition is true, else when it isn't, and else if adds more conditions. They're checked top to bottom and only the first true one runs.

    Step by step1 / 4
    1. ▶const grade = 76
    2. 2if (grade >= 85) {
    3. 3 console.log("Excellent")
    4. 4} else if (grade >= 65) {
    5. 5 console.log("Good")
    6. 6} else {
    7. 7 console.log("Keep going")
    8. 8}

    Variables

    grade76

    Output

    …
    JavaScript
    const grade = 76
    
    if (grade >= 85) {
      console.log("Excellent")
    } else if (grade >= 65) {
      console.log("Good")
    } else {
      console.log("Keep going")
    }

    Change the grade and see the result.

    A condition can be any value: JavaScript turns it into a boolean. if (name) means “if name isn't empty”.

    Important

    Order conditions from most specific to most general. If grade >= 65 came before grade >= 85, a 95 would get “Good” and never reach “Excellent”.

    Interview question

    How do you reduce deeply nested ifs?

    Order the lines

    Order it: above 30 print Hot, otherwise Nice.

    1. Click the lines in the right order

    What's the output?

    const x = 10
    if (x > 5) {
      console.log("A")
    } else if (x > 8) {
      console.log("B")
    }

    What will this code print?

    Exercise

    Print Adult if age is 18 or more, otherwise Minor.

    Expected output: Adult

    JavaScript
    const age = 20
    

    Learn more from

    • javascript.info: Conditional branchingjavascript.info
    • MDN: if...elsedeveloper.mozilla.org

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousNumbers and MathNextswitch and the ternary operator
    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.