Course contentsShow
← JavaScript
Lesson 2362 of 2,72348. Working with Binary DataFree lesson

What Are Blob and File?

Learn the difference between Blob (immutable binary data) and File (a Blob with filename and metadata).

What Are Blob and File?

You'll learn: The fundamental difference between Blob (immutable binary data containers) and File (Blobs with filename and metadata).

Understanding Blob

A Blob (Binary Large Object) is an immutable object that represents raw binary data in JavaScript. Think of it as a sealed container holding bytes—once created, you cannot modify its contents. Blobs are perfect for handling any kind of binary data: images, audio, video, or arbitrary byte sequences.

// Creating a Blob from text
const blob = new Blob(['Hello, world!'], { type: 'text/plain' });

console.log(blob.size);  // 13 (bytes)
console.log(blob.type);  // "text/plain"

Blobs are opaque—you can't directly access their bytes without converting them (using methods we'll cover later). They're designed for storage and transfer, not manipulation.

Understanding File

A File is simply a specialized Blob with additional metadata: a filename and last modified timestamp. When a user selects a file through an <input type="file"> element, you receive File objects.

// Files typically come from user input, but you can create them manually:
const file = new File(['Content here'], 'document.txt', {
  type: 'text/plain',
  lastModified: Date.now()
});

console.log(file.name);          // "document.txt"
console.log(file.lastModified);  // timestamp
console.log(file.size);          // 12
console.log(file.type);          // "text/plain"

Think of it this way: all Files are Blobs, but not all Blobs are Files. File inherits from Blob and adds file-specific properties.

The Relationship

Since File extends Blob, you can use them interchangeably in most APIs. Both are immutable binary containers—the only difference is whether you need to track filename and modification date.

Key Takeaway: Blob represents immutable binary data, while File is a Blob with a name and timestamp—use Blob for raw data, File when dealing with actual user files.