Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

280
Views
Why var keyword is used here?

Here in the below function, we are converting a data url to blob.

Actually I am writing a component that can crop an image...if I use const..then the screen freezes ... and nothing happens...only after using var it seems to be working.

const dataURLtoBlob = (dataurl) => {
  var arr = dataurl.split(",");
  var mime = arr[0].match(/:(.*?);/)[1];
  var bstr = atob(arr[1]);
  var n = bstr.length;
  var u8arr = new Uint8Array(n);
  n--;

  while (n) {
    u8arr[n] = bstr.charCodeAt(n);
  }
  return new Blob([u8arr], { type: mime });
};

Why var is used here? Is it because var can be reassigned and modified?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

In javascript there are 3 ways to declare a variable, var, let, const.

var is global scoped, which means it can be read on the whole function if you declare it inside it, so even if you declared a variable inside the while you wrote you could read it outside it.

let is block scoped, which means it can only be read from the block you declared it in. So if you declared a variable on the while you wrote you could only read it inside the while block.

And const is just like let but it can't be reassigned.

In your case all your variables are declared on the same block and are never reassigned, so let, var and const would work the same way. The most correct way to declare them would be const though, as they are never reassigned, but all would work.

Here's more info: https://www.geeksforgeeks.org/difference-between-var-let-and-const-keywords-in-javascript/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!