Frontend development

Stage 2 · Lesson 2 of 10

Functions and scope

JavaScript and the browser

In , functions are values. You can store them in variables, pass them to other functions and return them from functions. That is how callbacks, and all work.

Learn the three ways to write one: function declarations, function expressions and . Declarations behave as if they were moved to the top of their scope, which is called , so you can call them before the line that defines them.

Scope decides where a variable is visible. let and const follow block scope: a variable declared inside an if or a loop does not exist outside it. An inner function can read the variables of the functions around it.

Common traprelying on globals and shared variables, which makes code that works alone break when combined with other code.

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?