jQuery has matured as the de facto standard js library. However time has passed and interesting new frameworks like Zepto.js have appeared. Can they challenge jQuery's predominance?
Pngy is a bit of jQuery that allows you to load images of different file sizes based on a page’s load speed. So, if the load speed is slow, Pngy can load your small image. If it’s fast, it can load a hi-res image. It’s kinda like a ping test in Javascript.
The Play framework makes it easier to build Web applications with Java and Scala
Finally a Java Web framework made by Web developers. Discover a clean alternative
to bloated enterprise Java stacks. Play focuses on developer productivity and
targets RESTful architectures.
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 undefined — for (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.
(function f(){
function f(){ return 1; }
return f();
function f(){ return 2; }
})();
function f(){ return f; }
new f() instanceof f;
with (function(x, undefined){}) length;
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.