Last active
June 1, 2016 14:11
-
-
Save mjc-gh/95a339a85710c278ba7f to your computer and use it in GitHub Desktop.
JavaScript Code Examples
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
// 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); |
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
// 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 |
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
// 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