As @NagaJolokia points out, delete
is behaving differently in the Firebug console because the console is using eval()
to execute the code.
You can see the same effect in action if you test a delete
both in normal code and under eval()
. Save this page and load it in any browser with the developer console open:
<!DOCTYPE html>
<html>
<head>
<title>Eval/Delete Test</title>
<script>
console.log( 'Normal code, a = 1' );
var a = 1;
console.log( 'a is', typeof a, a );
console.log( 'window.a is', typeof window.a, window.a );
console.log( 'delete a OK?', delete a );
console.log( 'delete window.a OK?', delete window.a );
console.log( 'a is now', typeof a, window.a );
console.log( 'window.a is now', typeof window.a, window.a );
console.log( ' ' );
console.log( 'Eval code, b = 1' );
eval( 'var b = 1;' );
console.log( 'delete b OK?', delete b );
console.log( 'b is now', typeof b, window.b );
</script>
</head>
<body>
</body>
</html>
The code will log:
Normal code, a = 1
a is number 1
window.a is number 1
delete a OK? false
delete window.a OK? false
a is now number 1
window.a is now number 1
Eval code, b = 1
delete b OK? true
b is now undefined undefined
I also made a fiddle with the same code ready to run. It produces the same output as above. The fiddle includes Firebug Lite, so you don't need to open the developer console.
For a more thorough explanation, see NagaJolokia's answer and the Firebug confusion section of this article.