News for hackers. Stuff that matters.
Re:Show HN: A Javascript quiz that explores how javascript s... by tantalor on Thursday August 23, 2012 @12:58AM (#4420979)
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 s... by dschoon on Wednesday September 05, 2012 @04:12AM (#4478443)
Yeah, I agree with the other comments -- the greatest JS scoping gotcha involves unbound methods.

    var o = { a:13, add:function(b){ return this.a + b; } };
    o.add(42); // => `55`
    var add = o.add;
    add(42); // => `NaN`, because `this.a` is (presumably) `undefined`
    var a = 3;
    add(42); // => `45`, because `this.a` is resolved to `window.a`, as `window` is the global variable used as the method context when we call an unbound function (which is stupid (`null` would have been a way better choice, Brandon)).
This is the sort of thing you learn and just get over to reach the level of javascript mastery. Yeah, some things are silly. But you know what? You only get to write one language to access the dynamic web.
Re:Show HN: A Javascript quiz that explores how javascript s... by dschoon on Wednesday September 05, 2012 @04:14AM (#4478452)
For unknown reasons, ARC has truncated my code-comment. It read:

// => `45`, because `this.a` is resolved to `window.a`, as `window` is the global variable used as the method context when we call an unbound function (which is stupid (`null` would have been a way better choice, Brandon)).

Re:Show HN: A Javascript quiz that explores how javascript s... by droppedonjapan_ on Friday August 24, 2012 @05:21PM (#4429752)
You might want to consider including something about how passing objects between functions can be by reference or value for object oriented Javascript programming.
Re:Show HN: A Javascript quiz that explores how javascript s... by suyash on Sunday August 26, 2012 @02:59PM (#4435889)
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 s... by japrescott on Monday August 27, 2012 @03:44AM (#4437844)
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 s... by japrescott on Monday August 27, 2012 @03:54AM (#4437863)
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!

Re:Show HN: A Javascript quiz that explores how javascript s... by theuiguru on Friday August 24, 2012 @10:48AM (#4427800)
Excellent quiz to test your knowledge on global and local variables.
Re:Show HN: A Javascript quiz that explores how javascript s... by pankajparashar on Wednesday September 05, 2012 @03:43AM (#4478380)
Good & Informative quiz....Especially the tutorials section.
Re:Show HN: A Javascript quiz that explores how javascript s... by Vishnudas on Saturday August 25, 2012 @11:43AM (#4432325)
Nice Quiz. I just attempted with all right :)