Interviewing a JavaScript engineer

At my last place of work, LiveJournal, I conducted lots of JavaScript interviews and by writing this post I want to share the experience. We did focus more on JS, so there are no HTML/CSS questions here.

It is a good idea to start with a general and small task: to write a recursion. It has nothing to do with the language itself, but it helps to see if the candidate is able to do basic programming.

General programming

var arr = ['a', 1, 2, [3, 'b', 4, [5, 6, 'c']], 'd', 7, [8, 9]];  

How would you count the sum of all the numbers, including subarrays?

Next, one more general question, checks the knowledge of data structures.

var arr = ['banana', 'apple', 'orange', 'banana', 'tomato', 'apple'];  

How would you filter unique items inside the array?

If the answer involves using Array.prototype.indexOf, ask about how it could be done faster (hint: hashes). Optionally talk about algorithmic complexity.

JS basics

How would you change the context of the function? Talk about call, apply, bind.

Type checking in JS: talk about typeof and instanceOf operators, constructor property, how Object.prototype.toString could be useful.

Bonus question, explain the result of an expression

Function instanceof Object === Object instanceof Function  

Async

The second most important thing in my opinion is handling async code.

Lets say we have multiple links inside the array, and we want to send an ajax request to all of them and get a callback when everything is done.

var arr = ['/url1', '/url2' /* , … */ ];  

If the candidate uses promises, ask how it could be done without them.

Network

List every way the browser (using HTML, JS or CSS) can communicate with the server.

Here, the candidate should talk about XHR, script tag injection (JSONP), iframe (crossdomain issues, using postMessage), websockets, image beacons (new Image()).

Prototype

I don’t consider prototypical inheritance very useful in everyday code, but it is a must-know theory.

Compare these ways of inheritance. What are the downsides?

  1. Button.prototype = new Component();
  2. Button.prototype = Component.prototype;
  3. Button.prototype = Object.create(Component.prototype);

Tricks

Trick questions are something that involves hacking, knowing browsing specifics, etc. Not that easy coming up with an answer by yourself, requires article reading background :-)

Lets say we are writing a library or an external script, which will be used on lots of sites. On one of them, some crazy dude has done

window.addEventListener = null;  

and in our library we heavily rely on that method. Is there a way to fix things?

And another one, completely useless in production code, but a nice puzzle to solve:

Define such a, that expression

(a == 0) && (a == 1) && (a == 2)

would resolve to true.

Things to discuss

After all the technical stuff, it is nice to hear the candidate opinions about some general front-end topics, like

  • Client-side templating
  • Dependency management, CommonJS vs AMD
  • Building single page apps, strong and weak sides of Angular, Ember, Backbone
  • Code style and quality, unit testing

Refreshing the knowledge

On a side note, I want this article to be a refreshing point for everyone, who writes JS. Don't worry if there is stuff you have no idea about.

I would recommend rereading one of the best JS books - JavaScript Patterns by Stoyan Stefanov. Deep parts of language could be explored via some classic quizes, check Juriy Zaytsev, Nicholas Zakas, Dmitry Soshnikov, James Padolsey, Stephen Stchur, Dmitry Baranovskiy.

In the end, my best advice for ones trying to get a job in front-end: don't be afraid to do interviews and do lots of them. Even when I was perfectly happy with my job, I went to talk to the guys from another companies just to see what other people are doing, what tech stack do they have. Also do a pet project.

And if you are the one conducting interview, remember that your final decision should not only come from how the person answered to the technical questions. You'll probably work with this person side by side, so behaviour, communication and humor matters a lot.

~~~

Discussion at Reddit

comments powered by Disqus