Skip to content
Learn Netverks

Lesson

Step 3/36 8% through track

how-js-runs

How JavaScript runs in the browser

Last reviewed May 28, 2026 Content v20260528
Track mode
client_javascript
Means
In-browser JS
Reading
~1 min
Level
beginner

This lesson

This lesson teaches How JavaScript runs in the browser—the ideas, syntax, and habits you need before moving on in JavaScript.

Without a solid grasp of How JavaScript runs in the browser, you will repeat mistakes in JavaScript exercises and on real pages or scripts.

You will apply How JavaScript runs in the browser in contexts like: Browsers, Node.js services, edge workers, and tooling ecosystems (bundlers, test runners).

Run JavaScript in the in-browser sandbox, use the terminal output panel, and verify with MCQs.

Early in the track—complete this before layout, scripting, or architecture lessons that assume these basics.

The browser downloads HTML, builds the DOM, fetches scripts, then executes JavaScript on the main thread (unless you use Web Workers).

Parse → compile → run

  1. HTML parser builds DOM tree
  2. Script tags trigger download and execution
  3. Engine compiles to bytecode/machine code (JIT)
  4. Your code can read/mutate DOM and call Web APIs

defer and async

<script defer> runs after HTML parse. async downloads in parallel and runs when ready—order vs blocking matters for bugs.

Important interview questions and answers

  1. Q: What is the DOM?
    A: Live tree representation of the document scripts can change.
  2. Q: Why block the main thread?
    A: Long loops freeze UI—use async patterns or workers.

Self-check

  1. What happens before your script can query #app?
  2. When use defer on scripts?

Tip: Re-run the playground code for how-js-runs and tweak one line before the MCQs.

Interview prep

What is the DOM?

Live document tree the browser builds from HTML.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs in your browser in a sandboxed frame. Backend runners appear when this track’s profile allows them.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • What would you log to verify this behavior?
  • What breaks if you run this before the DOM is ready?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump