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

193
Views
A Variable in JS is not deleted but here is no error?

I have a variable. var variable; It is variable="Hello World";. Now, without using var and deleting it:

document.write(myVar);
delete myVar;
console.log("This should be an error because myVar has been deleted: ");
console.log(myVar);
<!--This is my module-->
<script>
  myVar = "Hello";
</script>

But with 'use strict';, there is no error with delete, and no error even though it cannot delete a var?

console.log("My Code Is Running");
delete myVar; 
if (!myVar){
document.write("Var Has Been Deleted");
}
console.log("My Code Is Done");

// Why does it not write "Var Has Been Deleted"?
// There is no 'use strict' to stop the delete.
<script>
'use strict';
var myVar = "Hello World";
</script>
What is happening?

Thanks in advance

about 4 years ago · Juan Pablo Isaza
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!