133

What are good questions to determine if applicant is really a pro JavaScript (browser side) developer ?

Questions that can distinguish if someone is not an ad-hoc JavaScript programmer, but is really doing professional JavaScript development, object-oriented, reusable, and maintainable.

Please provide answers, so an intermediate and ad-hoc JavaScript programmers can interview someone more experienced, coming up with answers to quite few of those advanced questions will elude me. Please avoid open questions.

Please keep one interview question/answer per SO answer for better reading experience and easier interview preparation.

Aardvark
  • 8,474
  • 7
  • 46
  • 64
Janusz Skonieczny
  • 17,642
  • 11
  • 55
  • 63
  • 21
    Never have an intermediate JS developer interview someone that's supposed to be more advanced! That's just crazy. Have someone qualified do the interviewing. – James Mar 22 '10 at 12:41
  • 22
    @J-P -- so if your senior developer quits, then you're just screwed? – tvanfosson Mar 22 '10 at 12:43
  • 15
    @J-P I'm trying to employ someone better than myself. It's a small startup, so I do not have better choice, unless I use outside help... but then I would have to interview him ;) – Janusz Skonieczny Mar 22 '10 at 12:47
  • The alternate questions you asked DO have answers, check the comments. – DisgruntledGoat Mar 22 '10 at 12:47
  • 13
    @J-P: If you’re just hiring people that are at most as good as you are, one day you will be surrounded by stupid idiots. Always try to hire someone who is better than you. – Gumbo Mar 22 '10 at 12:49
  • Maybe it woudl be easier for us to suggest if you give a bit more detail, for example is this for a website?, if so, this perosn you want to hire must have worked somewhere else, if i was you then I would go and chekc if it throws any errors, if it degrades gracefully, how did he/she maanged the browser hell, etc – roundcrisis Mar 30 '10 at 18:11
  • @michael myers: I think this question is a good question. I don't see the option to vote to reopen? Perhaps this is because it was closed by a moderator. I would like to see you remove your moderator close vote and let the community decide if it is worthy or not. It has 21 up-votes, and this is something I encounter daily. Hiring Junior developers over and over and firing them when they don't meet expectations is `not constructive`. This question however, is. Please re-open. – Nick Feb 28 '13 at 01:52
  • 1
    @Nick: The problem is that this question is too broad in scope and has no correct answer (see the [faq#dontask]'s comments on the subject). It is well suited for a blog post, but not so well suited for this Q&A format. In olden days we might have migrated to [Programmers.se], but after numerous threats of bodily harm from the Programmers mods we've had to change our ways. – Michael Myers Feb 28 '13 at 16:26
  • List of questions: https://www.toptal.com/javascript/interview-questions – vsync Sep 07 '18 at 14:33

8 Answers8

119

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.

bcherry
  • 7,150
  • 2
  • 28
  • 37
  • 4
    Good question. Small nitpick: I believe you mean "return result" instead of "return i". Pro-tip: Set up a nice little test environment to test code before posting ;-) – MisterMister Apr 08 '10 at 20:37
  • 4
    wow, that's a silly mistake. I test most of my code at jsFiddle before posting, but didn't test this one. Thanks :) – bcherry Apr 08 '10 at 20:50
  • 5
    The sum function should be resilient to non number types without throwing errors. In addition it should be able to handle numbers as strings for extra credit. – Abadaba Dec 19 '12 at 06:25
  • 2
    +1 for great mention and distrinction about finding out whether they are a good programmer. – Demonslay335 Nov 06 '13 at 17:33
  • 3
    This line: for (i = 0, l = arguments.length; i < l; i++) is bad because arguments.length will be evaluated every iteration. If you assign l = arguments.length before the for loop it is better. Right? – thomallen Apr 25 '14 at 17:05
  • 2
    @thomallen Your thinking is in the right place, but in this case `arguments.length` will only be evaluated once. Notice that the OP assigns it to `l` in the first statement of the `for` loop, before the first semicolon. Those expressions are only evaluated once. The second expression is evaluated on each iteration, which is only checking `i < l` – Stephen Jul 23 '14 at 18:26
  • @Stephen, yeah you're right I missed that. – thomallen Jul 23 '14 at 22:53
  • 1
    For the `sum` question, a good answer might be `function sum () { return [].slice.call(arguments).reduce(function (a, b) { return a + b; }, 0); }` – hawkharris Oct 31 '14 at 22:19
  • 1
    @hawkharris this answer is four years old, but these days I'd be happy to see people using newer stuff in JS like `.reduce` as long as they show an understanding of how it's not going to work in older browsers without polyfill. – bcherry Nov 17 '14 at 22:35
  • 1
    why bother with `sum.apply(null, data);`? we are not using any object's property anyways. – Surender Thakran Feb 16 '15 at 07:06
  • @SurenderThakran it shows that the candidate understands JavaScript functions at a deeper level than its similarities to other programming languages. If they don't know how to use arguments or how to invoke functions with more control then it suggests they may be a JS novice (no matter how capable they are at programming in general). This question is specifically asking for good strategies to interview advanced JS programmers, so this sort of question is very appropriate (there are at least a few dozen other good ways to test for this, too) – bcherry Feb 16 '15 at 20:07
  • I would have just done this: https://gist.github.com/ajkochanowicz/3097e2404c47b70daaa8 – Adam Grant May 06 '15 at 03:53
  • @ajkochanowicz yeah, `reduce` is a great choice today. this answer and context is over 5 years old at this point so it's a little out of date - there are probably better questions that you could use today as well. – bcherry May 06 '15 at 05:46
  • @bcherry fair point. – Adam Grant May 06 '15 at 18:04
  • These days you can just use something like `let data = [1,2,3]; sum(...data);`. Both of your questions are great questions, but I would move on to ensure they understand `this` and "prototypal inheritance" ( although I'm of the school of thought that this mechanism should be referred to as "delegation": http://git.io/vcJq4 ). – Jordan Sep 27 '15 at 16:21
  • this *l = arguments.length;* increase the performance. Recommend declare outside the for. – Ezequiel De Simone Oct 10 '17 at 13:18
95

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
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
pramodc84
  • 1,576
  • 2
  • 25
  • 33
  • 17
    this is for hiring JS Gurus. – Andreas May 05 '10 at 08:48
  • 1
    @andreas - Yes. Super set of questions. We can choose subset of these appropriately – pramodc84 May 05 '10 at 08:52
  • 22
    Be prepared for a JS developer to say something like this: JavaScript doesn't have associative arrays. JavaScript does, however, have object literals, which can be used like associative arrays. Also, objects' properties can be accessed using either dot notation or square brackets and strings. – Christopher Parker Aug 30 '12 at 12:59
  • 8
    These are baseline for someone who would call themselves a 'JavaScript Developer'. I think the depth of the answer is how you'd gauge them as a Guru or not. – Ryan Ore Jul 25 '13 at 18:55
  • @pramodc84 Why is extending array a bad idea? What about those future functions like map and ForEach? – Aran Mulholland Oct 09 '13 at 05:41
  • @AranMulholland Please take a look at http://stackoverflow.com/questions/8859828/javascript-what-dangers-are-in-extending-array-prototype – pramodc84 Oct 09 '13 at 09:43
  • 8
    You mean "Prototypal Inheritance." Common mistake. – wizzard Nov 22 '13 at 23:33
  • Here is a collection of questions: https://github.com/khan4019/front-end-Interview-Questions – Jhankar Mahbub Jun 22 '14 at 23:42
  • 4
    @wizzard you meant 'typical mistake' :p – Nick Sep 05 '14 at 17:17
  • @pramodc84 you seriously need to link the buttons with the pages :) – Aslam May 03 '16 at 08:52
  • @hunzaboy I didn't get that – pramodc84 May 04 '16 at 04:58
  • Sorry it was for @khanSharp – Aslam May 04 '16 at 08:52
  • 1
    Nobody actually says associative array, javascript people don't think of objects as arrays. In fact technically js doesn't have associative arrays since indexes have to be numbers. If you said "what's a hashmap?" or a "key-value object" everyone would understand. Also no one says "Classic Inheritance", if you said "Class Inheritance" people would understand. I'm not into throwing people off just because they don't use old comp science lingo. Also nobody extends global arrays or objects, and private variables don't strictly exist, the scope question is enough imo. – Dominic Jan 24 '18 at 10:01
24

Ask about "this". This is one good question which can be true test of JavaScript developer.

Anil Namde
  • 6,452
  • 11
  • 63
  • 100
18

(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.

Matt
  • 43,482
  • 6
  • 101
  • 102
  • 5
    @Tim Down: certainly, but if you find a reputable package, then nearly all parts of the package will have been reviewed by capable people. And as a user of an open source package, you can submit corrections when you find mistakes, adding your expertise as well. – PanCrit Mar 30 '10 at 18:11
  • True, know the wheel - but don't always use the same tires for different terrains. Eg. Why use the entire jQuery lib when all you need is Ajax transport etc (for your project) - http://microjs.com – Ali Feb 25 '14 at 01:01
  • 1
    The answer to this question is a question itself - why do we use an IDE and not simple notepad for editing our code? :) – Navin Israni May 28 '14 at 17:24
10

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
Janusz Skonieczny
  • 17,642
  • 11
  • 55
  • 63
Jonny Buchanan
  • 61,926
  • 17
  • 143
  • 150
  • 1
    THE best question to hire an architect-level JS guy :) – Navin Israni May 28 '14 at 17:40
  • First of all, convince me a person with JS turned-off is worth investing in in the real web and not dark-web. those users are probably overly-paranoid or clueless about using a browser and toggled JS off by mistake, either way, their chances of converting are slim to none. – vsync Sep 07 '18 at 14:25
  • Clearly the best way to see if someone is good at their day do day job is to ask them about something that never happens in their day to day job. Also you should also ask them how they would program for people who don't have electricity at home. – Bernardo Dec 06 '20 at 15:53
6

Ask how accidental closures might cause memory leaks in IE.

Janusz Skonieczny
  • 17,642
  • 11
  • 55
  • 63
Robusto
  • 31,447
  • 8
  • 56
  • 77
6

Ask "What unit testing framework do you use? and why?"

You can decide if actually using a testing framework is really necessary, but the conversation might tell you a lot about how expert the person is.

tvanfosson
  • 524,688
  • 99
  • 697
  • 795
0

intermediate programmers should have technical mastery of their tools.

if he's passed the technical phone screen-esque questions above, make him sketch out something stupid on the spot, like an ajax url shortner. then grill him on his portfolio. no amazing portfolio = intermediate developer in this domain and not the guy you want in charge of your shiny new project.

Dustin Getz
  • 21,282
  • 15
  • 82
  • 131
  • 5
    Portfolios is a poor metric at best - in today's world, JS is a perfectly-accepted tool in the enterprise world, where projects probably beat any portfolio you might see, and where public repos aren't a thing. – Ilya Ayzenshtok Dec 06 '16 at 17:55
  • 1
    @IlyaAyzenshtok THIS is part of my dilemma. Hard for me to show off a portfolio when 99% of my work is proprietary/behind a pay wall/internal... – Spartacus Dec 01 '17 at 21:14
  • 1
    @Spartacus - you can take screenshots and explain the interviewer your rule in it and hurdles along the way. regarding open-source projects, they are a great way to assess a person *before* an interview to adjust questions relative to the person's coding level seen in projects. – vsync Sep 07 '18 at 14:29