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>
Thanks in advance