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
and x = 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:
function sum() {
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):
var data = [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.