Please explain the rationale for this simple javascript interview question.

Consider this program:

(function(x){ delete x; return x; })(1); 

What is the conclusion?

This is, as I expected, 1 , not undefined . I thought that x purely within the scope of the function, and deleting it inside the function should make it inaccessible outside of it.

Can someone tell a little about this?

+4
source share
1 answer

See the delete manual:

The delete operator deletes an object property

and

If expression does not evaluate the property, delete does nothing.

A variable is not a property.

+11
source

All Articles