Sunday, September 18, 2011

Javascript QA

What is the main difference between window.onload and onDocumentReady?

Both functions are used to perform tasks when the page is loaded in the browser but they have important differences. Most importantly, “window.onload” will execute code when browser has loaded the DOM tree and all other resources like images, objects, etc, while onDocumentReady allows you to execute code when only the DOM tree has been built, without waiting for images to load. Thus, you can start scripting agains the DOM much quicker with onDocumentReady. Another important difference is that window.onload is not cross-browser compatible while using something like jQuery’s document.ready() will work nicely on all browsers.

What is the difference between undefined value and null value?

In JavaScript, undefined means that a value has been declared but has not yet been assigned a value, such as null, which can be assigned to a variable as a representation of no value. If a value is null, it was assigned programmatically, as JavaScript never sets a value to null on its own. Also, undefined and null are two different types: null is an object while undefined is a type itself (undefined).

Explain the difference between synchronous and asynchronous JS request?

Most importantly, synchronous request blocks JavaScript engine until the interaction with the server is complete. The user cannot click away, cancel request, or go to another tab during this time. It is bad for user experience and that is why we have AsynchronousJAX.

Explain briefly the difference between normal array and associative arrays?

This kind of a question could be rephrased as “explain the difference between a['one']=’dog’ and a[one]=’dog’” because the main difference between a normal array in JavaScript and associative arrays is that associative arrays use Strings instead of Integer numbers as index. But this is also kind of a trick question as JavaScript does not support associative arrays, they are objects and not really an array


Prototype inheritance vs Classic inheritance
Closure.
Why extending built in JavaScript objects (like how Prototype library does) is not a good idea.
Difference between document load event vs document ready event.
What are the different JavaScript frameworks you have used. And more importantly, which library do you prefer and why?
Event delegation
Cross Browser Scripting a. What is browser detection? What is feature detection? Which one is preferred?
Optimizing JavaScript heavy pages
Some sort of code test.

No comments:

Post a Comment