My Problem With ‘Tricky’ Javascript Interview Questions
I was reading this article yesterday and I didn’t do very well in answering the question that apparently 90% of Javascript developers get wrong. This is an interview question and I have to admit if I didn’t get a job because I didn’t answer this question correctly then I would be pretty annoyed.
I will expand on my reasons below but the basic premise of my answer is ‘this is not realistic of something you encounter in the field’ so why is it so important that it finds a place in a job interview?
When working in a codebase with many developers then rarely do you want ‘clever’ to be the favoured choice.
Why do these questions find a place in a job interview?
The best answer I can give for this is it helps reveal a candidates true understanding of the nuances of the Javascript language. Whilst this may be true on some levels does it give enough insight into the candidates relevant knowledge? It certainly could be interesting to hear the candidate speak out loud about how they are thinking about answering this question.
123[‘toString’].length + ‘123’ = ?
How they go about finding the length. How they concatenate a number and a string. Certainly interesting. Maybe a little insightful. Even a little fun (if the interviewer is a little on the masochistic side and likes to see candidates squirm under pressure). But relevant in the real day to day life of a Javascript developer? Not so much.
We Don’t Need Cleverness
As I have developed more and more in different code bases I have come to realise that simplicity is your friend. Don’t get me wrong, I like a clever solution as much as the next developer but when working in a codebase with many developers then rarely do you want ‘clever’ to be the favoured choice.
If I were to see this code in a Pull Request I would question it immediately. You can tell just from looking at it and knowing it’s Javascript that it is going to behave strangely. What you don’t want in a shared codebase are things behaving strangely and having areas of unpredictability. Whittling your code down to the most concise version it can be at the sake of readability is not going to help anyone.
Why Do People Like These Questions?
I think part of it is down to Javascript itself. It’s a language with some weird quirks. Things like this:
console.log(typeof null); // Output: 'object'
console.log(typeof NaN); // Output: 'number'
console.log(1 + '1'); // Output: '11'
console.log(1 - '1'); // Output: 0
console.log(0.1 + 0.2); // Output: 0.30000000000000004
These unexpected properties of Javascript just baffle people and some people really get excited by this and then want to see how much other so called Javascript developers know about it. I guess it’s a game of one-upmanship.
Don’t Base A Hiring Decision On One Of These Questions
I’ve read enough stories recently about “I didn’t get this job because I got this question wrong”. I don’t believe that for a second and if it’s true then that is a very scary prospect and you probably don’t want to be working for a company like that anyway.
I’ve hired enough people that I know the decision is never based on the answer to one question. If you had a great interview process, submitted a stellar technical assessment and made a fantastic impression then you would still get the job even if you answered a tricky Javascript question wrong.
If you are in the hiring chair and someone doesn’t answer a tricky Javascript question correctly then don’t give it too much wait. For sure you can take it into consideration but it certainly shouldn’t be a deciding factor. There are so many aspects to being a Javascript developer including manipulating data, working with UI components, working within different frameworks, working with client side state, working with apis, working with end users to understand requirements etc etc etc that not knowing a particular quirk really isn’t a big deal in the grand scheme of things.
Conclusion
Whilst I think it is important to know about the quirks of Javascript especially if you are working with it on a day to day basis, I don’t think it should hold too much sway in an interview process.
Being a modern day Javascript developer requires many skills and the whole suite of required skills should be assessed in an interview process and not just these edge case quirks.
Subscribe
If you liked this blog post you can subscribe to receive emails every time I publish. I publish every Monday morning at 8:30 Central European Time.
About me
I am a Frontend Developer working mainly with React and Typescript in my day-to-day professional life. I love exploring new tools and libraries and love the Javascript Ecosystem.
I like to write blog posts that share exciting new tools I’ve discovered, how-to articles, and also the occasional opinion piece.
I live in Prague in the Czech Republic with my family.
Check out the original blog post on my blog.