Created
September 7, 2012 05:09
-
-
Save leopic/3663357 to your computer and use it in GitHub Desktop.
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
<html> | |
<head> | |
<title>js test</title> | |
</head> | |
<body> | |
<h1>leo</h1> | |
</body> | |
<script> | |
console.log('---'); | |
// 0: what's printed here? | |
var myOutput = 'myOutput'; | |
console.log(this || myOutput); | |
// 1: why does this work? | |
printMyContent('hola mundo'); | |
function printMyContent(string) { | |
console.log(string); | |
} | |
console.log('---'); | |
// 2: what's the output of this? | |
function logThis(){ | |
console.log(this.name || this); | |
} | |
logThis(); | |
console.log('---'); | |
// 3: what's the output this time? | |
function Header() { | |
this.name = document.querySelectorAll('h1')[0].firstChild.nodeValue; | |
}; | |
var newHeader = new Header(); | |
logThis.apply(newHeader); | |
// why wasn't this used in #3 | |
console.log(newHeader.name); | |
console.log('---'); | |
// 4: what's going on here? | |
(function() { | |
console.log('goat'); | |
})(); | |
// when would you use this? | |
console.log('---'); | |
// 5: what's the output here? why? | |
if(!!' ') { | |
console.log('a'); | |
} else { | |
console.log('b'); | |
} | |
console.log('---'); | |
// 6: what's the output here? why? | |
console.log(['101', 1, 2, (11 + ''), '20'].sort()); | |
// how would you fix it? | |
console.log('---'); | |
// 7: why does this work? | |
function myFunc(e){ | |
return toUpp(); | |
function toUpp() { | |
return console.log(e.toUpperCase()); | |
} | |
} | |
myFunc('leo'); | |
console.log('---'); | |
// 8: why did myVar changed it's value? how would you avoid this? | |
var myVar = 'house'; | |
function calc(x) { | |
myVar = 'home'; | |
return x++; | |
} | |
console.log(myVar); | |
calc(3); | |
console.log(myVar); | |
// 9: declare a class in JS | |
// 10: create an instance of that class | |
// 11: add a new method to the object, not the instance | |
// 12: create a new instance of class that uses the new method | |
</script> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment