Pro Javascript Programmer Interview Questions (with Answers)
Solution 1:
Because JavaScript is such a small language, yet with incredible complexity, you should be able to ask relatively basic questions and find out if they are really that good based on their answers. For instance, my standard first question to gauge the rest of the interview is:
In JavaScript, what is the difference between
var x = 1
andx = 1
? Answer in as much or as little detail as you feel comfortable.
Novice JS programmers might have a basic answer about locals vs globals. Intermediate JS guys should definitely have that answer, and should probably mention function-level scope. Anyone calling themselves an "advanced" JS programmer should be prepared to talk about locals, implied globals, the window
object, function-scope, declaration hoisting, and scope chains. Furthermore, I'd love to hear about [[DontDelete]]
, hoisting precedence (parameters vs var
vs function
), and undefined
.
Another good question is to ask them to write a sum()
function that accepts any number of arguments, and returns their sum. Then, ask them to use that function (without modification) to sum all the values in an array. They should write a function that looks like this:
functionsum() {
var i, l, result = 0;
for (i = 0, l = arguments.length; i < l; i++) {
result += arguments[i];
}
return result;
}
sum(1,2,3); // 6
And they should invoke it on your array like this (context for apply
can be whatever, I usually use null
in that case):
vardata = [1,2,3];
sum.apply(null, data); // 6
If they've got those answers, they probably know their JavaScript. You should then proceed to asking them about non-JS specific stuff like testing, workflows, version control, etc. to find out if they're a good programmer.
Solution 2:
Basic JS programmming
Scope of variable
- What is
Associative Array
? How do we use it?
OOPS JS
Difference between Classic Inheritance and Prototypical Inheritance
- What is
difference between private variable, public variable and static variable
? How we achieve this in JS? - How to
add/remove properties to object
in run time? - How to achieve
inheritance
? - How to
extend built-in objects
? - Why
extending array is bad idea
?
DOM and JS
Difference between browser detection and feature detection
DOM Event Propagation
Event Delegation
Event bubbling V/s Event Capturing
Misc
Graceful Degradation V/s Progressive Enhancement
Solution 3:
(I'm assuming you mean browser-side JavaScript)
Ask him why, despite his infinite knowledge of JavaScript, it is still a good idea to use existing frameworks such as jQuery, Mootools, Prototype, etc.
Answer: Good coders code, great coders reuse. Thousands of man hours have been poured into these libraries to abstract DOM capabilities away from browser specific implementations. There's no reason to go through all of the different browser DOM headaches yourself just to reinvent the fixes.
Solution 4:
Ask them how they ensure their pages continue to be usable when the user has JavaScript turned off or JavaScript isn't available.
There's no One True Answer, but you're fishing for an answer talking about some strategies for Progressive Enhancement.
Progressive Enhancement consists of the following core principles:
- basic content should be accessible to all browsers
- basic functionality should be accessible to all browsers
- sparse, semantic markup contains all content
- enhanced layout is provided by externally linked CSS
- enhanced behavior is provided by [[Unobtrusive JavaScript|unobtrusive]], externally linked JavaScript
- end user browser preferences are respected
Solution 5:
Ask how accidental closures might cause memory leaks in IE.
Post a Comment for "Pro Javascript Programmer Interview Questions (with Answers)"