Created
January 28, 2014 20:17
-
-
Save gurunate/8675450 to your computer and use it in GitHub Desktop.
Javascript quiz - question #3 analysis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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