JavaScript Headers basics

Beginner
6 min read
Updated: Nov 2026

Definition and Usage

Create headers with new Headers(), then set/get/has. Header names are case-insensitive.

JavaScript Syntax

JavaScript
const h = new Headers();
h.set("Content-Type", "application/json");
console.log(h.has("content-type"));
console.log(h.get("Content-Type"));
Try it Editor

How It Works

  1. set. Stores the value.
  2. has/get. Case-insensitive lookup.

Examples

Example 1 — append

Multiple values.

JavaScript
const h = new Headers();
h.append("Accept", "text/html");
h.append("Accept", "application/json");
console.log(h.get("Accept"));
Try it Editor

How It Works

  1. append adds another value.

Frequently Asked Questions

Lookups are case-insensitive per the Headers API.
Yes—use the headers option with a Headers instance or a plain object.

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