To check if a variable is a blob in JavaScript, we can use the instanceof
operator.
For instance, we can write:
const myBlob = new Blob(['test text'], {
type: 'text/plain'
});
console.log(myBlob instanceof Blob)
to create a blob with:
const myBlob = new Blob(['test text'], {
type: 'text/plain'
});
We use the Blob
constructor with the content for the blob as the first argument.
Then 2nd argument is an object with the type
property to set the MIME type of the blob.
Then we use:
console.log(myBlob instanceof Blob)
to use the instanceof
operator check if myBlob
is a Blob
instance.
One reply on “How to Check if a Variable is a Blob in JavaScript?”
thank you !