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

    Objects · Lesson 25 of 45

    Methods and this

    Functions inside objects, and what this points to.

    8 minutes3 games

    A function inside an object is a method. Inside it, this refers to the object the method was called on (whatever is before the dot).

    JavaScript
    const account = {
      owner: "Hana",
      balance: 500,
      deposit(amount) {
        this.balance += amount
        return this.balance
      },
      describe() {
        return `${this.owner} has ${this.balance} EGP`
      },
    }
    
    account.deposit(250)
    console.log(account.describe())

    Don't use an arrow function as a method that needs this: arrows have no this of their own and take it from outside (usually undefined).

    JavaScript
    const timer = {
      seconds: 3,
      regular() { return typeof this.seconds },
      arrow: () => typeof this,
    }
    console.log(timer.regular()) // number
    console.log(timer.arrow())   // not the timer object

    Important

    this is decided when the function is called, not where it's written. Copy a method out, const f = account.describe, then call f(), and this is no longer account.

    Interview question

    What does this refer to in JavaScript?

    What's the output?

    const dog = {
      name: "Rex",
      speak() {
        return this.name + " barks"
      },
    }
    console.log(dog.speak())

    What will this code print?

    Complete the code

    Complete the method so it returns the full name.

    const person = {
      first: "Mona",
      last: "Adel",
      full() {
        return .first + " " + .last
      },
    }

    Exercise

    Add an area method returning width * height, then print it (24).

    Expected output: 24

    JavaScript
    const rect = {
      width: 4,
      height: 6,
    }
    

    Learn more from

    • javascript.info: Object methods, "this"javascript.info
    • MDN: thisdeveloper.mozilla.org

    Played 0 of 3 games

    Sign in to save your progress and earn XP.

    PreviousCopies and referencesNextJSON and optional chaining
    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.