Blob
Immutable raw data with a MIME type.
Blob represents raw file-like data. File extends Blob with a filename and metadata.
const blob = new Blob(["Hello"], { type: "text/plain" });
const text = await blob.text();
console.log(text);
JSON & Structured Data
Blob is useful when you need to create, read or download raw data in the browser. It can hold text, JSON, images, bytes and other file-like content.
File is a Blob with a name, lastModified timestamp and file-specific metadata. File objects often come from file inputs or drag-and-drop.
Blob methods such as text and arrayBuffer are asynchronous. Large files should be handled carefully to avoid memory problems.
Immutable raw data with a MIME type.
A Blob with a name and file metadata.
Reads Blob content as text.
Creates a temporary local URL for a Blob.
Examples
const url = URL.createObjectURL(blob);
link.href = url;
link.addEventListener("click", () => {
setTimeout(() => URL.revokeObjectURL(url), 0);
});
const url = URL.createObjectURL(blob); preview.src = url; // Not revoking many object URLs can waste memory.
Code patterns
These patterns focus on the data boundaries you will use constantly: JSON, URLs, forms, files, fetch objects and binary buffers.
Build file-like data in memory.
const blob = new Blob(["Hello"], { type: "text/plain" });
Blob reading is asynchronous.
const text = await blob.text();
Add a filename around Blob content.
const file = new File(["Hello"], "message.txt", {
type: "text/plain"
});
Create and revoke temporary Blob URLs.
const url = URL.createObjectURL(blob); URL.revokeObjectURL(url);
Rules that matter
Structured data becomes reliable when every boundary is explicit: text to object, form to values, URL to parameters, response to JSON and bytes to meaning.
It can hold text or binary content.
File adds name and metadata.
Blob text and arrayBuffer return promises.
Temporary Blob URLs should be cleaned up.
Never trust uploaded file metadata alone.
Large blobs can pressure memory.
Production thinking
Blob and File make browser JavaScript capable of handling real files without immediately uploading them.
File previews and downloads should have clear labels, names and status text.
Production file handling should validate type, size and lifecycle of object URLs.
Generated downloads are not crawler content, but file metadata and labels still affect user trust.
Live code lab
The preview runs inside an isolated iframe. The JavaScript is placed inside the HTML editor for now, so every example stays together and remains easy to understand.
Mini assignment
Practice assignment
Try it yourself
Self-check
Structured data is safe only when you know where it came from, what shape it has and what conversion happened before use.