Live data from Hacker News

Show HN: A Javascript quiz that explores how javascript scopes its variables

madebyknight.com

1–10 of 12 posts

Re: Show HN: A Javascript quiz that explores how javascript scopes its variables

#2
Since your quiz applies equally to any JavaScript engine, why not replace "window" with "this"?

See https://developer.mozilla.org/en-US/docs/JavaScript/Referenc...

> In the global context (outside of any function), this refers to the global object, whether in strict mode or not.

Re: Show HN: A Javascript quiz that explores how javascript scopes its variables

#7

You might want to consider including something about how passing objects between functions can be by reference or value for object oriented Javascript programming.

JavaScript only supports pass by value, @ author: Nice quiz, I failed the last one, it would be nice to add more quizes and test users knowledge of function scoping, just like the commenter said, since functions can be passed around like objects, function scoping is another tricky one to master for beginners.

Re: Show HN: A Javascript quiz that explores how javascript scopes its variables

#8
post #7

You might want to consider including something about how passing objects between functions can be by reference or value for object oriented Javascript programming.

JavaScript only supports pass by value, @ author: Nice quiz, I failed the last one, it would be nice to add more quizes and test users knowledge of function scoping, just like the commenter said, since functions can be passed around like objects, function scoping is another tricky one to master for beginners.

not true. boolean, strings, numbers (int, float) are passed by value, while Objects, Arrays and Functions are passed by reference!

Re: Show HN: A Javascript quiz that explores how javascript scopes its variables

#9
veryvery superb quiz! I like the way you mix questions with a tutorial, not just "HA, you suck, wrong", but really give detailed explanations, even when the correct answer is given. Maybe you can add some questions with strange return values or some "what happens if you modify the passed-in object within a function?";

function(){ var fn2=function(){} if (fn2()){ alert("nobody ever calls me"); } else{ alert("stop calling me!"); } } (no return value is a falsy value)

var data={a:"cow"}; function update(obj){ obj.a="fish"; } update(data); alert(data.a); //"fish"

vs.

var data="cow"; function update(str){ str="fish"; } update(data); alert(data); //"cow"

keep up the great work!

Post reply on HN