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

    Type conversion

    Number, String, Boolean, and the values that count as false.

    8 minutes3 games

    Sometimes a number arrives as text (like a value typed into a form) and you need to calculate with it. JavaScript converts types in two ways:

    • Explicit (you ask for it): Number("42"), String(42), Boolean(1).
    • Implicit (JavaScript does it for you): like "5" * 2 giving 10.
    JavaScript
    const input = "42"
    console.log(input + 8)          // "428": joined
    console.log(Number(input) + 8)  // 50
    console.log(Number("12px"))     // NaN
    console.log(parseInt("12px"))   // 12
    console.log(String(99) + "!")   // "99!"

    Important

    NaN means “Not a Number”; it's what you get converting something that isn't a number. Oddly, typeof NaN is "number" and NaN === NaN is false. Detect it with Number.isNaN(x).

    Truthy and falsy

    In any condition JavaScript turns the value into a boolean. Only 6 values count as false (they're falsy); everything else is truthy:

    falsy =

    false[0]
    0[1]
    ""[2]
    null[3]
    undefined[4]
    NaN[5]

    Even "0", "false", [] and {} are truthy.

    JavaScript
    console.log(Boolean(""))     // false
    console.log(Boolean("0"))    // true
    console.log(Boolean([]))     // true
    
    const name = ""
    if (!name) {
      console.log("Please enter your name")
    }

    Interview question

    What is [] == false, and why?

    What's the output?

    console.log("10" * 2)
    console.log("10" + 2)

    What will this code print?

    Quick question

    Which value is truthy?

    Exercise

    Both values arrive as text. Print their sum as a number (30).

    Expected output: 30

    JavaScript
    const a = "12"
    const b = "18"
    

    Learn more from

    • javascript.info: Type Conversionsjavascript.info
    • MDN: Truthydeveloper.mozilla.org
    • MDN: Falsydeveloper.mozilla.org
    • MDN: NaNdeveloper.mozilla.org

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousData typesNextArithmetic and assignment
    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.