Frontend development

Stage 2 · Lesson 5 of 10

How this works

JavaScript and the browser

The gets its value from how a function is called, not where it is written. Called as obj.method(), this is obj. Called as a plain function, it is undefined in strict mode and in modules.

have no this of their own. They use the one from the surrounding code, which makes them handy for inside methods. Passing a method as a callback, such as setTimeout(user.greet, 100), loses its this.

Calling bind, or wrapping the call in an arrow function, fixes that. You will meet this in classes, in (where it is the element) and in older library code. Modern framework code uses it less, so the goal is to predict it, not to design around it.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

  • CoursePaid
    Grokking JavaScript Fundamentals

    Design Gurus · Beginner · $50

    Guided beginner course on the language core, with quizzes after every chapter

  • GuideFree
    JavaScript.info

    Ilya Kantor

    Free and thorough: Part 1 for the language, Part 2 for the DOM and events, Part 3 for fetch

Practise

  • Thirty small browser projects with no framework to hide behind

  • Free JavaScript curriculum exercises for daily reps on the language core

Keep handy

  • JavaScript and Web API reference, including fetch, the DOM and events

Also worth your time

Mark this stage as not done?