I tried delete a variable in javascript using delete operator, but found some issue. Can you guys please explain the below code, and why it is happening
>
The delete operator removes a property from an object not the normal variables. Here in this case the object is global implicitly.
On a side note:-
When you write var x = 5 then it declares variable x in current scope ie, in execution context. If declaration appears in a function then local variable is declared and if it's in global scope then global variable is declared.
Whereas when you say x = 5,then it is merely a property assignment. It first tries to resolve x against scope chain. If it finds x anywhere in that scope chain then it performs assignment otherwise it creates x property on a global object.