Geeks On The Moon

« Short Replies |
Main
| 10 Reasons Why Good Documentation Has To Be Huge »

February 07, 2010

Geeks On The Moon

Moon

01:56 PM | Permalink

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341d3df553ef0128777162bf970c

Listed below are links to weblogs that reference Geeks On The Moon:

Comments

Was it already his second check in on the moon to get the badge? ;).

Posted by:

Rick Mans |

February 07, 2010 at 04:10 PM

Verify your Comment

Previewing your Comment

Posted by:

 | 

This is only a preview. Your comment has not yet been posted.

Your comment could not be posted. Error type:
Your comment has been saved. Comments are moderated and will not appear until approved by the author. Post another comment

The letters and numbers you entered did not match the image. Please try again.

As a final step before posting your comment, enter the letters and numbers you see in the image below. This prevents automated programs from posting comments.

Having trouble reading this image? View an alternate.

Dont you love Foursquare?

Perfection kills » Javascript quiz

I was recently reminded about Dmitry Baranovsky’s Javascript test, when N. Zakas answered and explained it in a blog post. First time I saw those questions explained was by Richard Cornford in comp.lang.javascript, although not as thoroughly as by Nicholas.

I decided to come up with my own little quiz. I wanted to keep question not very obscure, practical, yet challenging. They would also cover wider range of topics.

Host objects

Contrary to Dmitry’s test, quiz does not involve host objects (e.g. window), as their behavior is unspecified and can vary sporadically across implementations. We are talking about pure ECMAScript (3rd ed.) behavior. Now, it’s worth pointing out that sometimes implementations deviate from the standard collectively, forming their own, de-facto standard. An example of this is for-in statement, where none of the popular implementations throw TypeError when expression evalutes to null or undefinedfor (var prop in null) { ... } — and instead just silently ignore it. I tried to avoid these non-standard cases. Every question has a correct answer that can be reproduced in at least one of the major implementations.

So what are we testing?

Not a lot really. Quiz mainly focuses on knowledge of scoping, function expressions (and how they differ from function declarations), references, process of variable and function declaration, order of evaluation, and a couple more things like delete operator and object instantiation. These are all relatively simple concepts, which I think every professional Javascript developer should know. Most of these are applied in practice quite often. Ideally, even if you can’t answer a question, you should be able to infer answer from specs (without executing the snippet). When creating these questions, I made sure I can answer each one of them off the top of my head, to keep things relatively simple.

Note, however, that not all questions are very practical, so don’t worry if you can’t answer some of them. We don’t often use with statement, for example, so failing to know/remember its exact behavior is understandable.

Few notes about code

  • Assuming ECMAScript 3rd edition (not 5th)
  • Implementation quirks do not count (assuming standard behavior only)
  • Every snippet is run as a global code (not as eval or function one)
  • There are no other variables declared (and host environment is not extended with anything beyond what’s defined in specs)
  • Answer should correspond to exact return value of entire expression/statement (or last line)
  • “Error” in answer indicates that overall snippet results in a runtime error

Quiz

Please make sure you select answer in each question, as lack of answer is not checked and counts as failure. The final score is simply a number of wrong answers, less is better. Quiz requires Javascript to be enabled.

  1. (function(){       return typeof arguments;    })();
    • “object”
    • “array”
    • “arguments”
    • “undefined”
  2. var f = function g(){ return 23; };    typeof g();
    • “number”
    • “undefined”
    • “function”
    • Error
  3. (function(x){      delete x;      return x;    })(1);
    • 1
    • null
    • undefined
    • Error
  4. var y = 1, x = y = typeof x;    x;
    • 1
    • “number”
    • undefined
    • “undefined”
  5. (function f(f){       return typeof f();     })(function(){ return 1; });
    • “number”
    • “undefined”
    • “function”
    • Error
  6. var foo = {       bar: function() { return this.baz; },       baz: 1    };    (function(){       return typeof arguments[0]();    })(foo.bar);
    • “undefined”
    • “object”
    • “number”
    • “function”
  7. var foo = {      bar: function(){ return this.baz; },      baz: 1    }    typeof (f = foo.bar)();
    • “undefined”
    • “object”
    • “number”
    • “function”
  8. var f = (function f(){ return "1"; }, function g(){ return 2; })();    typeof f;
    • “string”
    • “number”
    • “function”
    • “undefined”
  9. var x = 1;    if (function f(){}) {      x += typeof f;    }    x;
    • 1
    • “1function”
    • “1undefined”
    • NaN
  10. var x = [typeof x, typeof y][1];    typeof typeof x;
    • “number”
    • “string”
    • “undefined”
    • “object”
  11. (function(foo){      return typeof foo.bar;    })({ foo: { bar: 1 } });
    • “undefined”
    • “object”
    • “number”
    • Error
  12. (function f(){      function f(){ return 1; }      return f();      function f(){ return 2; }    })();
    • 1
    • 2
    • Error (e.g. “Too much recursion”)
    • undefined
  13. function f(){ return f; }    new f() instanceof f;
    • true
    • false
  14. with (function(x, undefined){}) length;
    • 1
    • 2
    • undefined
    • Error

You’ve got 0 answers wrong.
Flawless victory.

Let’s see the score!

I hope you liked it. Please leave your score in the comments. I’ll try to explain these questions sometime in a near future, unless someone else does it before me. Meanwhile, you can take a look at my articles on function expressions and delete operator, understanding which would help you answer some of these questions, and more importantly, explain their answers.

Think you kow JavaScript? Then try this 😉

Google: Forms & Landing Pages are Key

February 8th, 2010

Google: Forms & Landing Pages are Key

by Joshua Porter  |   Comments  |  shortlink: http://bokardo.com/p/1606

A fascinating post by Googler Gavin Doolan:

If you are considering making changes to your website design, take a moment to consider the potential revenue impact of your redesign. (This graph) shows a theoretical overview of the ROI impact of various parts of your website.

I love that: “theoretical overview”. In other words, they really have no idea. But, if this is true, think about how it would rewire the way the design world works. Almost all money is pushed into technology and branding. Homepage, site redesigns, and custom CMSes are the cash cows of the design industry…imagine if most projects were not about those things but about simply improving these decision-oriented pages. Probably won’t happen, but fun to think about.

via Conversion Room: Improve your web-forms and increase conversions.

Check out my latest project: Make them Care!, a book on designing great sign-up experiences. Get reminded when it’s published.

Previous

Dreamers of Day

Next

Forget the homepage, focus on your form design!