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

    String methods

    Slice, search, replace and clean up text.

    8 minutes4 games

    Strings come with built-in methods. These are the ones you'll use every day:

    MethodWhat it doesExample

    toUpperCase() / toLowerCase()

    upper/lower case

    "hi".toUpperCase() → "HI"

    trim()

    removes spaces at both ends

    " a ".trim() → "a"

    includes(x)

    contains x?

    "cat".includes("a") → true

    startsWith(x)

    starts with x?

    "https".startsWith("http")

    indexOf(x)

    position of x (or -1)

    "code".indexOf("d") → 2

    slice(a, b)

    part from a up to b

    "SeaCode".slice(0, 3) → "Sea"

    split(sep)

    splits into an array

    "a,b".split(",")

    replaceAll(a, b)

    replaces every a with b

    "1-2-3".replaceAll("-", "/")

    padStart(n, c)

    pads to length n

    "7".padStart(2, "0") → "07"

    JavaScript
    const email = "  Ahmed@SeaCode.tech "
    const clean = email.trim().toLowerCase()
    console.log(clean)
    console.log(clean.includes("@"))
    console.log(clean.split("@"))
    console.log(clean.slice(0, clean.indexOf("@")))
    
    const time = "9:5"
    const [h, m] = time.split(":")
    console.log(`${h.padStart(2, "0")}:${m.padStart(2, "0")}`)

    You can chain methods: trim().toLowerCase().

    Important

    slice accepts negative numbers that count from the end: "report.pdf".slice(-3) returns "pdf".

    Interview question

    Write one line that reverses a string ("abc" → "cba").

    What's the output?

    console.log("JavaScript".slice(0, 4))

    What will this code print?

    Complete the code

    Split the text at every comma.

    const tags = "html,css,js"
    console.log(tags.(","))

    Spot the bug

    This code checks the email has an @. Where's the mistake?

    Exercise

    Reverse "seacode" and print it (edocaes).

    Expected output: edocaes

    JavaScript
    const word = "seacode"
    

    Learn more from

    • MDN: Stringdeveloper.mozilla.org
    • javascript.info: Stringsjavascript.info

    Played 0 of 4 games

    Sign in to save your progress and earn XP.

    PreviousStrings and template literalsNextNumbers and Math
    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.