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.
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.
How would you change the context of the function? Talk about
Type checking in JS: talk about
constructor property, how
Object.prototype.toString could be useful.
Bonus question, explain the result of an expression
Function instanceof Object === Object instanceof Function
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.
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 (
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?
Button.prototype = new Component();
Button.prototype = Component.prototype;
Button.prototype = Object.create(Component.prototype);
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:
a, that expression
(a == 0) && (a == 1) && (a == 2)
would resolve to
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.
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 RedditTweet comments powered by Disqus