-
-
Save jfairbank/3679aa2d03d4165a6a1988d327e6e171 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
// Question: Explain the difference in how x is defined in these three examples | |
// Sample A | |
function a(){ | |
x = 1; | |
} | |
// Sample B | |
function b(){ | |
var x = 1; | |
} | |
// Sample C | |
x = 2; | |
function c(){ | |
var x = 1; | |
} |
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: In what order will the strings be printed to the console when this file is executed? | |
// Assume fetch is a function that requests a URL and returns a Promise | |
function fetchData() { | |
return fetch('/data').then(function() { | |
console.log('a'); | |
}); | |
} | |
console.log('c'); | |
fetchData().then(function() { | |
console.log('d'); | |
}); | |
console.log('b'); |
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