NetFXHarmonics JavaScript Quiz
Wednesday, January 9, 2008
In response to Meebo's popular "JavaScript Ninja" interview questions, I created a JavaScript Quiz for beginning, intermediate, and advanced JavaScript developers. Feel free to use it in interviews, quizzing, or for your own personal edification. I will admit one or two portions are a bit obscure, but the same could be said of a couple of Meebo's questions.
// JavaScript Quiz // Created by David Betz @ http://www.netfxharmonics.com/ // What is the purpose of this first line? (easy) var A = window.A || { }; A.B = { c:4, d:function(x) { return { e:A.B.c*x, f:4 } } }; function M( ) { this.p=8; return { c: function( ) { // How can you return the value of M::p? (medium) } } } function N( ) { } /////////////////////////////////////////////////////// // Why is this function syntax here? (medium) (function( ) { var addEventListener = function(e,f) { if(window.addEventListener) { window.addEventListener(e,f,false); } else if(window.attachEvent) { window.attachEvent('on'+e, f); } }; addEventListener('load', function( ) { var v = 2; var w = 4; (function( ) { var v = 8; w = 16; })( ); // What are the values of v and w? (easy) alert('v:'+ v); alert('w:'+ w); /////////////////////////////////////////////////////// var t = A.B.d(3).e*A.B.d(3).f; // What is the value of t? (easy) alert('t:'+ t); /////////////////////////////////////////////////////// var a = new N( ); N.prototype.B = function(y) { return { q:Math.pow(4,y) } }; var b = new N( ); var r = a.B(2).q; var s = b.B(2).q; // What are the values of r and s? (easy) alert('r:'+ r); alert('s:'+ s); (function( ) { r = s; var s = 3; })( ); // What is the value of r? (hard) alert('r:'+ r); alert('s:'+ s); /////////////////////////////////////////////////////// (function( ) { var m; var n; var a = function(o,f,a) { f.call(o, a); }; a({ y:4 }, function(x) { m=this.y*x; }, 3); a = { x:1, y:2, z:4 }; (function(r, s, t) { n=this.x*r+this.y*s+this.z*t; }).apply(a, [1, 2, 3]); // What are the values of m and n? (medium) alert('m:'+ m); alert('n:'+ n); })( ) }); })( );
If you regularly work with Modern JavaScript, need to make sense of the code that Microsoft ASP.NET AJAX throws out, want to make sense of what your AJAX framework is doing, would like to understand the mechanics of AJAX application, or would like to being creating rich, powerful, and efficient AJAX applications, then there is only book that I can recommend: AdvancED DOM Scripting: Dynamic Web Design Techniques by Jeffery Sambell. This book is phenomenal.
It covers all the intermediate and advanced JavaScript required to interpret the above JavaScript code as well as all the training you would need to create your own powerful AJAX framework. This is an incredibly exhaustive book that is perfect for anyone who desires to dramatically increase their JavaScript, DOM scripting, and AJAX skills. I've been pushing this book for quite a while now and for good reason. Seriously, buy this book!




