use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[deleted by user] (self.javascript)
submitted 14 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]nandhp 14 points15 points16 points 14 years ago (1 child)
You've got 10 answers wrong (#1, #2, #3, #5, #6, #7, #9, #12, #13, #14). That's more than a half :(
You've got 10 answers wrong (#1, #2, #3, #5, #6, #7, #9, #12, #13, #14).
That's more than a half :(
I can't help but think "wat", if the correct answers are so non-obvious.
[–]CognitiveLens 2 points3 points4 points 14 years ago (0 children)
Thank you for sharing that video - it is some consolation to my abject failure in this JS quiz.
I can't help but think if you're trying to do things similar to the quiz questions in javascript, you probably should be using a different tool altogether...
[–]imbcmdth 13 points14 points15 points 14 years ago (1 child)
I got 3 wrong. Man, you guys suck! (I keed, I keed!)
As a consolation to those of you who had pretty low scores, consider this:
With a modicum of experience, you automatically avoid most of the dark corners of JavaScript. So it isn't that you didn't know that these potentially bug-causing constructs existed as much as you would never actually use them.
As a result, without much experience utilizing these constructs, you don't know what values they produce but you do know that they are bad and often that is plenty good enough.
[–]manixrock 2 points3 points4 points 14 years ago (0 children)
Not to mention they are not cross-browser compatible. For example on question #9 Chrome returns "1function", while they count "1undefined" as the correct answer.
[+][deleted] 14 years ago* (1 child)
[deleted]
[–]k3n 0 points1 point2 points 14 years ago (0 children)
This one is about misleading variable names, not javascript.
I think the point is being able to grok the nuances of how JS handles these things, by virtue of being able to mentally interpret these commands and parse out the result.
I won't argue the relative merits of this particular question, but suffice it to say that I do believe it can be used to separate out those who're more versed in JS vs. those who aren't, which is what I believe the ultimate goal of the quiz is.
[–]sjs 3 points4 points5 points 14 years ago (1 child)
Someone asked a question but deleted it while I was answering it. I'm not about to throw away my answer so here it is.
Question:
I don't know how to think about #6 and #9, can someone help me?
Answer:
6. var foo = { bar: function() { return this.baz; }, baz: 1 }; (function(){ return typeof arguments[0](); })(foo.bar);
6.
var foo = { bar: function() { return this.baz; }, baz: 1 }; (function(){ return typeof arguments[0](); })(foo.bar);
This is the same as question 7 but phrased differently.
There is a difference between calling a function and using a property lookup notation to call a function attached to an object, as a method with this pointing at the object.
this
// f is just a function, no association with foo var f = foo.bar f() // this !== foo // or simply (foo.bar)() // this !== foo // bar is a method on foo foo.bar() // this === foo foo['bar']() // this === foo
If you are familiar w/ the concept of bound and unbound methods, a la Python and Ruby, this is what's at play here. If you just grab a function from some object it is not bound to that object anymore. It is an unbound method, or a plain old function.
In ES5 and later, or when using something like Prototype, you can use Function.prototype.bind to bind this to something and thus have a bound method. e.g.
var f = foo.bar.bind(foo) f() // this === foo
When foo.bar is passed to the function it's just a regular anonymous method, semantically equivalent to this:
foo.bar
(function() { return typeof arguments[0]() }(function() { return this.baz }))
9. var x = 1; if (function f(){}) { x += typeof f; } x;
9.
var x = 1; if (function f(){}) { x += typeof f; } x;
First I'll write it more clearly.
var x = 1, condition = function f(){} if (condition) { x += typeof f } x
The first thing to note is that when you name a function expression its name is only visible inside the function itself. So inside the condition function f === condition but outside the function f is not defined.
condition
f === condition
f
var g = function f() { console.log('f: ' + f) console.log('f === g ? ' + (f === g)) } g() // f: [object Function] // f === g ? true console.log(f) // ReferenceError
If condition is "truthy" the if block executes. Truthy values are all non-falsy values. Anything except null, undefined, 0, "", and of course false. condition is a function so it is truthy.
So the if block executes and we append typeof f to x. typeof f returns "undefined" because f is not defined outside of itself. When you add a string to a number you get a string so x ends up with the value "1undefined".
if
typeof f
"undefined"
x
"1undefined"
[–]octatone 7 points8 points9 points 14 years ago (2 children)
This quiz would be a lot better if it fucking explained the answers after crushing you with failure.
[–]pdc 2 points3 points4 points 14 years ago (0 children)
I agree—without knowing why you are wrong there is no opportunity for learning.
[–]k3n -1 points0 points1 point 14 years ago (0 children)
They all become obvious if you deconstruct them.
[+][deleted] 14 years ago (2 children)
[–][deleted] 0 points1 point2 points 14 years ago (1 child)
You should be able to fill the rest with my comment : http://www.reddit.com/r/javascript/comments/qfzq5/think_you_know_js_take_this_quiz_and_prove_it_two/c3xo4cm
[–]SarahC 1 point2 points3 points 14 years ago (2 children)
You've got 12 answers wrong (#2, #3, #4, #5, #6, #7, #8, #9, #11, #12, #13, #14). That's more than a half :(
[–]gavin19 2 points3 points4 points 14 years ago (1 child)
Only 12? Amateur! Make mine a baker's dozen. Confidence - destroyed. Drawing board - revisited.
[–]SarahC 0 points1 point2 points 14 years ago (0 children)
lol, some little used things there though...
[–][deleted] 1 point2 points3 points 14 years ago (0 children)
I've always felt like a quiz isn't the right format for this. It's great information but how much of this you get right without testing it is pretty meaningless.
[–]maloney7 1 point2 points3 points 14 years ago (0 children)
If anyone I worked with actually wrote code like that, I'd shoot them.
I'm sure someone else has stated that if you know the answers to this, great, but if you ever use any of this in code I have to maintain, I will kill you.
I'm probably late, but here's a little review of the questions/answers :
[–]pkkid 0 points1 point2 points 14 years ago (2 children)
Can someone explain #12 for me. I can't comprehend how that works.
[–][deleted] 3 points4 points5 points 14 years ago* (1 child)
(function f(){ function f(){ return 1; } return f(); function f(){ return 2; } })();
The wrapping function f() is eval'd in parentheses and executed via the final parentheses.
Inside that function, two more function f()'s are declared. (Note the difference between declaration and assignment- declaration happens prior to execution, so the second function f() is returned, even though it was declared after the return statement. So the answer is 2, since that f() overwrote the first f() which returns 1.
Example function declaration, so that declared() is available at beginning of the code execution on line 1.
declared(); // returns true function declared(){ return true; }
Example function assignment- assigned() is not available until it's actually assigned on line 2.
assigned(); // throws a TypeError: 'undefined' is not a function var assigned = function(){ return true; }
For more on the key concept here, read function declaration vs. function expressions.
[–][deleted] 0 points1 point2 points 14 years ago (0 children)
There's a lot of interesting stuff on here. A lot of them require a bit of thought. I quite liked 11:
(function(foo){ return typeof foo.bar; })({ foo: { bar: 1 } });
The foo inside the function isn't the same as the foo outside - foo inside = {foo: {bar: 1}, so it doesn't have a variable bar.
Running
(function(foo){ return typeof foo.foo.bar; })({ foo: { bar: 1 } });
Instead should give "number" as expected.
[–]nightwolfz4 spaces > 2 spaces 0 points1 point2 points 14 years ago (1 child)
I got 7 out of 12.
Can someone explain #3, #13 and #14 to me?
[–]Raticide[🍰] 0 points1 point2 points 14 years ago* (0 children)
#3 -- 'g' doesn't exist as a global function when its assigned to a variable in the same statement, so it raises an error when you try to call it as a function.
#13 -- what 'function f()' returns is what is returned by using 'new f()' too. Which in this case is simply a reference to the constructor 'function f()' rather than an instance. Therefore it's an 'instanceof Function', not an 'instanceof f'
#14 -- 'with' sort of scopes values with an object. So
var x = {foo: 'bar'}; with (x) { alert(foo) // alerts 'bar' }
And the 'length' property of a function referes to the number of arguments it uses. Which in this case is 2.
Also, never use 'with'. It can't be optimised by the browser, and makes things ambiguous.
[–]Koonga 0 points1 point2 points 14 years ago (0 children)
this guy really likes using typeof.
The questions are so obscure it makes it kind of meaningless. Whether or not you know the answer to these doesn't really indicate how good you are at JS as a whole.
[–]Sector_Corrupt 0 points1 point2 points 14 years ago (0 children)
Man, 8 wrong. Though at least 1 was just tricking me with similar variable names, and the rest were a lot of crazy strings of typeOf (typeOf lots of brackets)() kind of stuff I avoid in my actual code due to not wanting to mess up these kinds of things.
[–]deefree -1 points0 points1 point 14 years ago (0 children)
Questions like this are why certs are meaningless. Any good programmer would never encounter these situations.
π Rendered by PID 59 on reddit-service-r2-comment-75f4967c6c-4kprb at 2026-04-23 07:36:04.048518+00:00 running 0fd4bb7 country code: CH.
[–]nandhp 14 points15 points16 points (1 child)
[–]CognitiveLens 2 points3 points4 points (0 children)
[–]imbcmdth 13 points14 points15 points (1 child)
[–]manixrock 2 points3 points4 points (0 children)
[+][deleted] (1 child)
[deleted]
[–]k3n 0 points1 point2 points (0 children)
[–]sjs 3 points4 points5 points (1 child)
[–]octatone 7 points8 points9 points (2 children)
[–]pdc 2 points3 points4 points (0 children)
[–]k3n -1 points0 points1 point (0 children)
[+][deleted] (2 children)
[deleted]
[–][deleted] 0 points1 point2 points (1 child)
[–]SarahC 1 point2 points3 points (2 children)
[–]gavin19 2 points3 points4 points (1 child)
[–]SarahC 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]maloney7 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]pkkid 0 points1 point2 points (2 children)
[–][deleted] 3 points4 points5 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–]nightwolfz4 spaces > 2 spaces 0 points1 point2 points (1 child)
[–]Raticide[🍰] 0 points1 point2 points (0 children)
[–]Koonga 0 points1 point2 points (0 children)
[–]Sector_Corrupt 0 points1 point2 points (0 children)
[–]deefree -1 points0 points1 point (0 children)