Home » Interview » 7 JavaScript Interview Questions [To Weed Out Imposters]

7 JavaScript Interview Questions [To Weed Out Imposters]

image

Last week, I posted 7 interview questions for C# programmers.  I guess I forgot that people can’t see in my brain.  So, let me be very explicit this time.  The “weed out the losers” questions are meant to do just that.  Weed out people who have absolutely no business even applying for the job.

You would be amazed at how many people interview for a job who have all kinds of cool buzzwords on their resume, but when you ask them about it, they know nothing about the subject.  I’m not sure if this is the recruiter who is representing them trying to help them out by beefing up the resume to get them in the door or if they actually do this themselves.  But, as someone who interviews, I have to have a way of making sure the applicant I’m interviewing is worth interviewing in the first place.  Hopefully, I can do this over the phone in less than a half an hour.

So, with that said, if your favorite question isn’t on this list, it is probably because it is a question I would save for some future interview.

Also, to those of you who may think that a technical interview doesn’t really tell you if the programmer is a good programmer or not, I have this to say…

You are right.  And when I was a younger programmer and was being interviewed with technical questions, I felt the same way.  But now that I’m on the other side of the table, I find that way too often, the people who can pass a technical interview are a lot more likely to be good programmers than the ones who can’t.

And finally, I would not rule out an applicant because he got a couple of questions wrong, or didn’t answer them exactly the way I expected.  But if couldn’t answer most of them, that would raise a huge red flag!

So, here are 7 JavaScript Interview Questions you should ask first.  Otherwise, you may be wasting your time.

What are two ways you might create an object in JavaScript?

This is a pretty simple question if you’ve been using JavaScript.  Shoot, you should even be able to guess at one of the answers.  But, still, in my experience, there are a lot of people who say they are JavaScript programmers who don’t know how to answer this question.

  • Use the “new” keyword to call a function.
  • Use the open/close curly braces.
    var o = {};

You might want to follow up with, “using the new keyword, at what point is the object created?”  But, as far as questions that weed out, I would consider that something that could wait until I’m really interviewing to discover how deep the applicant’s knowledge goes.

How would you create an array?

This is a similar level question to “How do you create an object.”  And yet, there are some who can answer the first who can’t answer this one.

While it is possible to create an array with

var myArray = new Array();

It is a long way of creating an array.  One would hope that the answer included using square brackets.

var myArray = [];

Once again, there are other questions we could ask, but since we only want to know that the applicant is worth further investigation, I would leave the array questioning here.

What is variable hoisting?

This one is a slightly harder question to answer, and I wouldn’t expect anyone to be able to answer this.  But again, we are trying to get a quick determination of the applicant’s skill level.  How well do they understand the language they claim to know?

Variable hoisting is the term that refers to the fact that no matter where a variable is declared in a scope, the JavaScript engine will move that declaration to the top of the scope.  If you declare a variable in the middle of a function, for example and assign a value to it all in one line:

function foo()
{
    // a bunch of code here
    var a = "abc";
}

The code that actually gets run would look like this:

function foo()
{
    var a;
    // a bunch of code
    a = "abc";
}

 

What are the dangers of global variables and how do you protect against it?

The danger of global variables is that someone else could create a variable with the same name and overwrite the variable you are using.  This is a bad idea in any language.

You prevent this in a number of ways.  The most common would be to create one global variable that all of your other variables live in:

var applicationName = {};

And then any time you need to create a global variable, you attach it to that object.

applicationName.myVariable = "abc";

The other way you can guard against this is by wrapping all of your code in a self-executing function so that any variables that are declared are declared within that function’s scope.

(function(){
   var a = "abc";
})();

In reality, you’ll probably end up using both methods.

How do you iterate through members in a JavaScript object?

for(var prop in obj){
    // bonus points for hasOwnProperty
    if(obj.hasOwnProperty(prop)){
        // do something here
    }
}

What is a closure?

A closure is what allows a function inside the scope of another function to still be able to see the variables declared in the outer scope even after everything else about that scope has disappeared.  Bonus points if they state something about the dangers of using a closure inside of a for/next loop without declaring a variable to hold the current value of the iteration variable.

Describe your experience unit testing JavaScript

Here we are just trying to find out if they’ve even done unit testing with JavaScript.  It is an open ended question with no particular right answer but it should tell you something in the process.

 

Other post in Interview

Related Post

  • 7 C# Interview Questions [That Weed Out The Losers!]7 C# Interview Questions [That Weed Out The Losers!] So, once again, the place I am currently working has been interviewing for some more programmers and we’ve had to laugh at some of the answers we’ve received on some pretty simple […]
  • Revisiting The Technical InterviewRevisiting The Technical Interview I’ve written about the technical interview before.  I’ve written both for and against code interviews.  And I’ve provided both C# and JavaScript questions to weed out fake programmers. But […]
  • 3 Reasons Responding To Useless Interview Questions Makes You Happier3 Reasons Responding To Useless Interview Questions Makes You Happier I’ve noticed a trend recently.  Someone will write a post about some technical interview question and someone will write a comment about how that’s such a dumb question that they wouldn’t […]
  • Cracking the Programmer’s Interview CodeCracking the Programmer’s Interview Code Several comments this week contribute to this week’s post. The first, and the one that pushed me to write this post, is a discussion over at Simple Programmer on a post called “Cracking […]
  • Your Programming Resume is GarbageYour Programming Resume is Garbage Over the last several years, I’ve had a chance to read a few Programming Resumes.  Or, I should say, TRY to read a few resumes.  But frankly, if the Programming Resume I typically see is […]

About Dave Bush

Dave Bush is a Full Stack ASP.NET developer focusing on ASP.NET, C#, Node.js, JavaScript, HTML, CSS, BootStrap, and Angular.JS. Does your team need additional help in any of the above? Contact Dave today.

2 Pingbacks/Trackbacks

  • James Parsons

    You have to be kidding me! People get this stuff wrong?

    • Sadly, yes.

    • Kevin O’Shaughnessy

      I have been interviewing senior developers recently. Unfortunately I’ve never reached the “what is a closure?” question. Considering they didn’t know what strict mode was, what linting was, what Jasmine is, or what hoisting was, there was not really any point in going any further…

      I have posted articles on my blog telling candidates what to do: http://zombiecodekill.com/2015/07/01/thoughts-on-interviewing-candidates/

      When I see someone’s CV the first thing I do is look them up on Github. If they’re not there I look them up on stackoverflow, and try to find a blog. If I can’t find any of those I look for a LinkedIn or Twitter account. This is very basic and easy and doesn’t take very long at all. I don’t understand why interviewees do not make the same minimal effort to find out something about their interviewers.

      • T’

        Because, typically, they don’t know their interviewers by name beforehand (and very often not even after the interview)?

        • No. But we always know the company name and few even go as far as finding out something about the company. Most recruiters will tell you who you will be meeting with.

          • Kevin O’Shaughnessy

            Absolutely. If the recruitment agency can’t tell you the name of the person who will be interviewing you, they aren’t doing their job properly and you should consider using a different agency in the future.

        • Recruiters have to tell you who you will be interviewing with. I always try to find out as much I can about them. It helps in the interview – you may find that you have something in common, like going to the same conferences / meetups, etc.

  • Its interesting and sad to know that people cant answer this basic of questions when applying for a job.

  • rbrtsmith84

    Overall a good article, but some of the answers can be expanded further – #1 and #2 you can also return objects and arrays from functions for a means of creation. Also Object.keys() is a more modern and cleaner way of iterating over an object’s own properties. Of course this is just a matter of opinion but I think a candidates understanding of ‘this’ and prototypes is also crucial. I also like to see developer who understand higher order functions – arguably JavaScripts best feature.

    • I would save these questions for the real interview. But, yes, they are important

      • rbrtsmith84

        That’s a good point, I guess like the title says, it’s good to have some preliminary questions to weed out the pretenders and get down to details in further interviews 🙂

  • Pingback: 7 Reasons Every Programmer Needs to Learn JavaScript()

  • Dokter Syarif

    nice article

  • Daniel Gutierrez

    Very good article. Quick question: a lot of companies now administer coding test during the hiring process. Do you think that solving one of these tests is a good way to prepare for the actual testing? This one for example: http://www.testdome.com/Programming-Tests/JavaScript/14

    • Any test you take should help you become a better programmer, so yes.

  • Pingback: Are You Average or Awesome? 9 Ways to Improve.()

  • Jay French

    One thing I try to do when I’m interviewing somewhere is try to make it a conversation more than just a fill in the blank exercise. That goes for both interviewing to get a job and interviewing candidates to hire at the place I work.

    One example would be highlighted if someone asked me what variable “hoisting” is. I can honestly say I understood that concept before reading this article, but I hadn’t heard that term before. So if I was asked that question in an interview (“What is variable hoisting?”) I would have said that I’m not familiar with the term, but if they could ask about the concept it represents I might know it by another name. And in this case I would have.

    Another example is patterns (singleton, etc). I tend to forget the names of the various design patterns (I can only remember singleton off the top of my head), but I understand the various patterns and have used all of them when they made sense. Just because I don’t remember their names should be far less important than being able to describe how they work and when each makes sense.

    Be careful asking questions that depend on knowing the “label” we put on certain concepts, and if the interviewee doesn’t know that label, try to explain it in conceptual terms. Obviously if they know the label it makes it easier and quicker, but that’s less important in the long run than knowing the underlying concept.

    • I use to have the same opinion. In fact, I once was known to proudly say, “If you want someone who can pass some sort of text book interview, I’m probably not your guy. If you want someone who can code circles around most of the developers you have working for you, let’s talk.”

      But, I’ve since come to see the value in being able to speak to questions using the proper technical terms.

      If I’m looking for a “Rock Star” programmer, I’ll expect you know something about the technical terms that are used, including names for design patterns.

      If I just want someone who can get code churned out, the bar will be a bit lower.

      Being able to answer both as the person being interviewed will give you a MUCH broader market. This isn’t about what is fair. It is about what will get you hired.

      • Jay French

        I’m not saying I don’t brush up on things like that before an interview. Obviously I want to make the best impression I can, so I do. But no matter how many times I’ve gone over a list of design patterns, the fact that I don’t actually use that information (the names of them) on a daily basis, I don’t remember them. I can still describe each one if you tell me the name, and I can use the one that makes sense in any given situation. And I’d put myself up against any rock star you want. 🙂

  • Anthony Tirop

    Am intermediate Js and Python programmer and finding this really helpful. Thanks for the update.