Reputation: 116333
In Chrome, this fiddle prints false
. However, the same code typed in the JavaScript console prints true
:
a = 1;
var a = 2;
console.log(delete a);
Why do I get different results depending on whether or not I'm using the Chrome console?
Upvotes: 3
Views: 85
Reputation: 23863
Because the Chrome console runs inside an eval
construct or something similar, rather than running in the global scope.
There is a lot of discussion about the delete
operator here on StackOverflow. A search for [javascript] delete
will help answer other questions that come up.
Upvotes: 1