JavaScript Response basics

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

After fetch, inspect response.status / response.ok, then consume the body once with json() or text().

JavaScript Syntax

JavaScript
const res = new Response("hi", { status: 200 });
console.log(res.status, res.ok);
res.text().then(console.log);
Try it Editor

How It Works

  1. status/ok. 200 is success.
  2. text(). Reads the body as string.

Examples

Example 1 — json()

Parse JSON bodies.

JavaScript
const res = new Response('{"n":3}');
res.json().then((d) => console.log(d.n));
Try it Editor

How It Works

  1. Body must be valid JSON.

Example 2 — Body one-shot

Cannot read twice without clone.

JavaScript
const res = new Response("x");
res.text().then((t) => console.log(t));
Try it Editor

How It Works

  1. Call clone() before a second read if needed.

Frequently Asked Questions

True when status is 200–299.
No. You get a Response with ok false.

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful