What is a Blob in JavaScript and How to Use it?

In this article, we will explore what is a blob in JavaScript and how to use it.

Discover the power of JavaScript Blob, a flexible and useful tool for working with binary data.

Learn how to easily create and use data blobs in your web applications.

What is a blob in JavaScript?

A blob is a way to store data in JavaScript. It stands for Binary Large Object and can hold different types of data, like text or binary data.

In addition to that, JavaScript blob is a container for binary data, allowing you to store and manipulate files as raw data.

This adaptable entity proves especially valuable when managing substantial data portions or overseeing file uploads.

Blobs are useful when you need to work with large files, like images or videos, because they can store the data efficiently.

When to use blob in JavaScript

Blobs are often used when working with large files or when transferring data between different parts of an application.

For example, you might use a blob to store an image file that a user uploads to your website, or to store the contents of a text file that you want to download from a server.

You can also use blobs to create URLs representing the object using the URL.createObjectURL() method.

How to use blob in JavaScript?

Here are some examples of how to use a blob in JavaScript:

Creating a blob from a string

let blob = new Blob(["Hi, welcome to itsourcecode!"], {type: 'text/plain'});

The example code above shows how to create a new blob object from a string of text.

The blob constructor is used to create the blob object, and the text data is passed in as an array.

Creating a blob from a typed array and strings

let hello = new Uint8Array([72, 101, 108, 108, 111]); // "Hello" in binary form
let blob = new Blob([hello, ' ', 'world'], {type: 'text/plain'});

Here, our example code shows how to create a new Blob object from a combination of a typed array and strings.

The blob constructor is used to create the blob object, and the data is passed in as an array.

Creating a URL representing the contents of a blob

let blob = new Blob(["Hi, welcome to itsourcecode!"], {type: 'text/plain'});
let blobURL = URL.createObjectURL(blob);

This example shows how to create a URL that represents the contents of a blob object.

The URL.createObjectURL() method is used to create the URL, and the blob object is passed in as an argument.

Downloading a dynamically-generated blob with “Hi, Welcome to Itsourcecode!” contents as a file

<a download="example.txt" href='#' id="link">Download</a>
<script>
    let blob = new Blob(["Hi, Welcome to Itsourcecode!"], {type: 'text/plain'});
    link.href = URL.createObjectURL(blob);
</script>

This example shows how to create an HTML page with a link that, when clicked, will download a text file containing the text “Hi, Welcome to Itsourcecode!”

The blob constructor is used to create a new Blob object containing the text data, and the URL.createObjectURL() method is used to create a URL for the blob object.

This URL is set as the href attribute of an element, which allows the user to download the file when the link is clicked.

How to create blob URL in JavaScript?

You can create a URL for a Blob object in JavaScript using the URL.createObjectURL() method.

This method takes a blob object as input and returns a URL that represents the data stored in the blob.

For example, let’s say you have some text data that you want to store in a blob and create a URL for.

First, you would create a new blob object called sampleBlob that contains the text data from the sampleString and pass in the text data as an array.

Here’s an illustration of how to create a blob URL from a string:

const sampleString = "Hi, Welcome to Itsourcecode!";
const sampleBlob = new Blob([sampleString ], {type: 'text/plain'});
const sampleBlobURL = URL.createObjectURL(sampleBlob);

Then, you would use the URL.createObjectURL() method to create a URL for the sampleBlob object and store it in the sampleBlobURL variable.

You can use this URL to reference the data stored in the blob in different ways, like setting it as the source of an image or using it as a link.

Here’s the complete example:

<!Doctype html>
<body>
<!-- download attribute forces the browser to download instead of navigating -->
<a download=" Example.txt" href='#' id="link">Download</a>

<script>
const sampleString = "Hi, Welcome to Itsourcecode!";
const sampleBlob = new Blob([sampleString], {type: 'text/plain'});
const sampleBlobURL = URL.createObjectURL(sampleBlob);

link.href = sampleBlobURL;
</script>
</body>

Output:

Conclusion

In conclusion, this article has delved into the concept of a blob in JavaScript, which stands for Binary Large Object.

A blob serves as a versatile container for storing various types of data, both text and binary, much like a receptacle for substantial information.

This article has highlighted the practical utility of JavaScript Blobs, particularly when dealing with sizable data portions or handling file uploads.

We also emphasized the use cases for blobs, particularly in managing large files such as images or videos, and outlined how to create and manipulate blobs within JavaScript.

We are hoping that this article provides you with enough information that helps you understand the blob JavaScript. 

If you want to dive into more JavaScript topics, check out the following articles:

Thank you for reading itsourcecoders 😊.

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.
Caren Bautista

Technical Writer at PIES IT Solution

Responsible for crafting clear, well-structured, and beginner-friendly content across the platform. Handles the writing, proofreading, and editorial review of tutorials, guides, and documentation to ensure every article is accurate, readable, and easy to follow.

Expertise: Technical Writing · Content Creation · Documentation · Editorial Writing · JavaScript · TypeScript · Python · Python Errors · HTTP Errors · MS Excel  · View all posts by Caren Bautista →

Leave a Comment