Interviewing With Me? Here’s an Easter Egg. I’ll ask you this JavaScript Question During the Interview.

We’re hiring in my group.

Cool, right?

So, I’m once again interviewing. Yay me.

Since I’m no longer running a group I don’t have to worry about any of the administrative type things (“this is what the company is about,” “this is what we do,” etc.) That’s good as it just allows me to test people on technology. That’s really my favorite part of the interview process anyway. Win.

The following is a tiny snippet I’ve been using to test people’s knowledge of JavaScript fundamentals.

Why share it here? For one thing it’s kind of interesting to me since it’s a very small snippet but it can expose a lot about the way the person approaches the language. Basically, if you can get this and you’re still pretty inexperienced you’ve probably read a book, taken a class or read a blog post or article written by someone smart. That’s a bonus.

And then there’s the Easter Egg part. Meaning, I’m still going to be using this going forward with the answer sitting right out here in the open. Why?

Here’s how I see it. If a candidate:

  1. Has researched me before interviewing with me
  2. Read enough of my blog to find this post
  3. Read it and learned enough about the topic to spit it back at me in the context of an interview- including the terrible, probing questions I will ask to try to get past the surface knowledge

So, even if they didn’t know the answer before reading this post they have some other positive qualities that more than make up for a bit of a hole in their technical knowledge.

In other words, there are two ways to get the right answer to this particular question. Either one is going to impress me.

Anyway, while we’re a jQuery shop, we also want people who know, you know, actual JavaScript, so I always include a pure JavaScript question to test people.

This is what I’ve been using. To me, this could be answerable by anyone that I’d want to hire who’s moved beyond the Search Google -> Copy -> Paste cycle of JavaScript development. Thanks to the jQuerys of the world, there are a lot of people who can do plenty of useful work who don’t know anything about how JavaScript actually works. That’s great, but if you’ve actually looked under the hood in the way that answering this question correctly implies you’re probably going to be a better, more useful fit.

Getting this wrong isn’t a killer in the process, of course. This is a more junior role, so I don’t need to have a candidate be a super expert at everything to make the grade.

Are you ready?

Here’s the code I show them:

[javascript]
alert([1,2,3,4,5].duplicator());
//outputs [1,2,3,4,5,1,2,3,4,5]
[/javascript]

The instructions are: Make that statement work.

The answer, if you know what’s what, can be very simple. Here’s an example:

[javascript]
Array.prototype.duplicator = function(){
return this.concat(this);
}
alert([1,2,3,4,5].duplicator());
[/javascript]

Simple, yes. The thing is, to get there you need to know about a few things that are Good to Know.

  • The original example uses an Array literal to create an array (some people don’t get that pattern)
  • The solutions returns a value and correctly uses this to bind to the Array
  • Using Array.prototype to extend the native Array with the useless duplicator() method

For the pirate/ninja/jedi crowd this might seem silly basic, but the plain fact is there are people out there who are making good money coding JavaScript who would fail at one or more of these hurdles. I can start to sort candidates into one or the other camp with just the one line.

Not too shabby.

And if they get the answer by reading this far? Hi, good luck with the rest of the interview (cue dramatic music and maniacal laughter)