Skip to content

Instantly share code, notes, and snippets.

@gurunate
Created January 28, 2014 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gurunate/8675450 to your computer and use it in GitHub Desktop.
Save gurunate/8675450 to your computer and use it in GitHub Desktop.
Javascript quiz - question #3 analysis
/*
Question: #3 (http://perfectionkills.com/javascript-quiz/)
(function(x){
delete x;
return x;
})(1);
A. 1 [correct]
B. null
C. undefined
D. Error
*/
// Analysis
// "The delete operator removes a property from an object."
// "delete is only effective on an object's properties. It has no effect on variable or function names."
// -- https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete
(function(x){
delete x;
console.log(x); // 1
return x;
})(1);
var y = 5; // declares a new variable, y
console.log(delete y); // false
console.log(y); // 5
z = 101; // creates the property z on the global object (i.e. window)
console.log(delete z); // true
console.log(z); // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment