Consider this program:
(function(x){
delete x;
return x;
})(1);
What is the output?
It happens to be 1
and not undefined
as I expected. I thought x
purely is in the scope of function and deleting it inside the function should have made it inaccessible to outside it.
Can someone throw a little light on this?
See the manual for delete:
The
delete
operator deletes a property of an object
and
If
expression
does not evaluate to a property,delete
does nothing.
A variable is not a property.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With