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

    Getting started · Lesson 2 of 45

    Variables: let, const and var

    How to store a value for later, and pick the right keyword.

    9 minutes4 games

    A variable is a named box where you keep a value for later. There are 3 ways to declare one:

    • const: the value won't change. Use it by default.
    • let: the value will change (a counter, a total, a state).
    • var: the old way. You'll see it in old code, but don't use it.
    name"Omar"const
    score15let

    Each variable is a name pointing at a value.

    Step by step1 / 4
    1. ▶const name = "Omar"
    2. 2let score = 10
    3. 3score = score + 5
    4. 4console.log(name, score)

    Variables

    name"Omar"

    Output

    …

    name is created with "Omar" and will never change.

    Changing a const throws TypeError: Assignment to constant variable.

    Why not var?

    constletvar

    Can change?

    No

    Yes

    Yes

    Scope

    block {}

    block {}

    function

    Use before declaring?

    error

    error

    gives undefined (confusing)

    Declare twice?

    error

    error

    allowed (risky)

    Naming rules

    A name starts with a letter, _ or $, has no spaces, and isn't a reserved word like let or if. The convention is camelCase: userName, totalPrice. JavaScript is case-sensitive: age and Age differ.

    Important

    Name variables after what they hold: price beats p, isLoggedIn beats flag. Code is read far more often than it's written.

    Interview question

    Can you change something inside an object declared with const?

    Quick question

    A product's price changes in a sale. How do you declare it?

    Spot the bug

    One line will throw an error. Click it.

    Complete the code

    Complete it: the student count grows, the course name is fixed.

     course = "JavaScript"
     students = 20
    students = students + 1

    Exercise

    Create balance with 100, add 50, and print it.

    Expected output: 150

    JavaScript
    // balance
    

    Learn more from

    • javascript.info: Variablesjavascript.info
    • MDN: letdeveloper.mozilla.org
    • MDN: constdeveloper.mozilla.org
    • javascript.info: The old "var"javascript.info

    Played 0 of 4 games

    Sign in to save your progress and earn XP.

    PreviousWhat is JavaScript?NextData types
    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.