Skip to content

Instantly share code, notes, and snippets.

@mjc-gh
Last active June 1, 2016 14:11
Show Gist options
  • Save mjc-gh/95a339a85710c278ba7f to your computer and use it in GitHub Desktop.
Save mjc-gh/95a339a85710c278ba7f to your computer and use it in GitHub Desktop.
JavaScript Code Examples
// Sample A
var x = y;
function y(){};
// Sample B
var a = b;
var b = function(){};
// Sample C
i = j;
j = function(){};
// Question: What is the value of x, a and i?
console.log(x, a, i);
// Sample A
function a(){
x = 1;
}
// Sample B
function b(){
var x = 1;
}
// Sample C
x = 2;
function c(){
var x = 1;
}
// Question: Explain the difference in how x is defined in these three examples
// User Constructor
function User(){
this.getName = function(){};
}
// Task Constructor
function Task(){}
Task.prototype.getSummary = function(){};
var user = new User();
var task = new Task();
// Question: What is the result of these console statements? Why is this the case?
console.log(user.hasOwnProperty('getName'));
console.log(task.hasOwnProperty('getSummary'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment