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

    Operators and strings · Lesson 6 of 45

    Comparison and logic

    ===, !==, &&, || and ??.

    8 minutes4 games

    Comparisons return true or false: >, <, >=, <=, === (exactly equal) and !== (not equal).

    Always use ===, not ==. == converts types before comparing and causes surprises, like 0 == "" being true.

    JavaScript
    console.log(5 === 5)     // true
    console.log(5 === "5")   // false: different types
    console.log(5 == "5")    // true: converted, avoid
    console.log("apple" < "banana") // true: dictionary order

    Logical operators

    OperatorMeaningExample

    &&

    and: both must be true

    age >= 18 && hasId

    ||

    or: one is enough

    isAdmin || isOwner

    !

    not

    !isLoggedIn

    ??

    fallback if null or undefined

    name ?? "Guest"

    JavaScript
    const age = 20
    const hasTicket = true
    console.log(age >= 18 && hasTicket) // true
    
    const nickname = null
    console.log(nickname ?? "Guest")     // Guest
    
    const count = 0
    console.log(count || 10)  // 10: 0 is falsy
    console.log(count ?? 10)  // 0: only null/undefined are replaced

    Important

    && and || stop as soon as they know the result (short-circuit): false && x never looks at x. You'll often see user && user.name.

    Interview question

    What's the difference between || and ?? for defaults?

    What's the output?

    console.log(true && false)
    console.log(true || false)
    console.log(!true)

    What will this code print?

    Quick question

    What is "3" === 3?

    Complete the code

    Print true if the age is from 13 to 19 (a teen).

    const age = 16
    console.log(age >= 13  age <= 19)

    Exercise

    Print username, or Anonymous if it's missing (use ??).

    Expected output: Anonymous

    JavaScript
    const username = undefined
    

    Learn more from

    • javascript.info: Comparisonsjavascript.info
    • javascript.info: Logical operatorsjavascript.info
    • javascript.info: Nullish coalescing operatorjavascript.info
    • MDN: Equality comparisons and samenessdeveloper.mozilla.org

    Played 0 of 4 games

    Sign in to save your progress and earn XP.

    PreviousArithmetic and assignmentNextStrings and template literals
    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.