Skip to content
Learn Netverks

Lesson

Step 23/36 64% through track

fetch-json-preview

fetch and JSON preview

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

This lesson

This lesson teaches fetch and JSON preview—the ideas, syntax, and habits you need before moving on in JavaScript.

Without a solid grasp of fetch and JSON preview, you will repeat mistakes in JavaScript exercises and on real pages or scripts.

You will apply fetch and JSON preview in contexts like: API calls, live dashboards, and form submissions without full page reloads.

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

When the previous lesson's MCQs feel easy and you can explain fetch and JSON preview in your own words.

fetch(url) requests HTTP resources. response.json() parses JSON bodies—common for APIs you'll build on Node.js.

Basic flow

const res = await fetch('/api/items');
if (!res.ok) throw new Error(res.status);
const data = await res.json();

In this playground, practice parsing with JSON.parse; real fetch runs in the browser tab.

CORS

Browsers block cross-origin responses unless server sends CORS headers—backend topic.

Important interview questions and answers

  1. Q: res.ok?
    A: True for status 200–299—still check before parsing.
  2. Q: JSON.parse vs json()?
    A: parse on string; json() on Response stream in fetch.

Self-check

  1. Why check res.ok?
  2. What is CORS in one sentence?

Challenge

Parse API-shaped JSON

  1. Parse the sample JSON string.
  2. Log items.length.
  3. Add a guard if items is missing.

Done when: your code handles missing items without throwing.

Interview prep

res.ok?

True for HTTP 2xx—check before parsing body.

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