How to Interview JavaScript Engineers

December 15, 2014 0 Comments by

In some JavaScript interviews you'll go over some of the core concepts of the language, like the prototype, constructor functions, scope, closures, and data types. You may cover some popular design patterns. The objective is two-fold. Make the questions open-ended enough to be able to identify the candidate's knowledge. Make the questions as specific as possible, to make it possible for the candidate to answer the question. That's the challenge.

Start with a primer in JavaScript. Talk about inheritance, prototypes, constructors, ES5, ES6, build tools, best practices, and be prepared to write some sample code.

What is this?

this is neither a reference to the function itself, nor is it a reference to the function's lexical scope. The this keyword is actually a binding that is made when a function is invoked, and what it references is determined entirely by the call-site where the function is called. It's execution context, the value at run-time.

Immutable Data Structures

Implement immutable objects with configurable, writable, seal and freeze. Seal will call preventExtensions and configurable false. Freeze calls seal and writable false.


These two examples are the same:

function Constructor(){}  
o = new Constructor 

o = Object.create(Constructor.prototype)  

Another good way to establish a candidate's expertise, is to ask them to implement their own way of doing something that's usually done with a popular JS library.

  1. Implement form validation. When you're doing this for a production site, you probably don't want to roll your own. You may be better off with a Backbone or jQuery plugin, or perhaps an Angular directive. Writing your own validation library will take longer, have less features, be less robust, and is more likely to have bugs. The few bytes you save will be negligible. You can establish a candidates familiarity with one line:

    However, that won't help much in determining their skill level. Let's start with a basic form: <form><input type=text required=required></form>

    Then a quick jQuery script to validate input: $(input).keyup -> $(@).val() != ''

  2. Implement a pub/sub module. If you're in jQuery you may use the built-in event methods, .on() and .off(). If you had to roll you're own, have a peak at how David Walsh gets this done.

// Define an immediate function
events = do ->  
  // Create a private object to store events
  topics = {}
  // Define method to handle subscribe 
  // This method accepts two arguments
  // a name for the event and an argument for the listener 

subscribe: (topic, listener) ->  
  // Create the topics object if it does not exist already
  topics[topic] = { queue: []} if (!topics[topic])
  // Provide a method to remove topic
remove: ->  
  delete topics[topic].queue[index]
  // Provide a method to publish a topic. This method accepts two 
  // arguments, the event name to publish to and associated data
publish: (topic, info) ->  
  // Leave if the topic doesn't exist or if there are no 
  // listeners queued up
  return if (!topics[topic] or !topics[topic].queue.length
  // Cycle through the topics queue and invoke the publish event
items = topics[topic].queue  
items.forEach (item) ->  
  item(info or {})
  1. Implement an extend method. A common way to do this is with the prototype method. To define properties on itself, an object can be extended with this method below borrowed from Underscore. Define a namespace that takes an argument:

    extend = (obj)->

    Return everything but the first entry of the array, to be used with the arguments object: = (array, index, guard) ->, if _.isUndefined(index) or guard then 1 else index)

Loop through the arguments:
for source in

Assign the value to the property of the object:
`obj[key] = val for key, val of source

Return the new object:

  1. Implement a factorial. This demonstrates how to use recursion.
# Define a function that accepts the interator as a parameter
factorial (n) ->

# Return 1 if the number is 0 or 1:<br>
return 1 if (n <= 1)

# Recursively invoke the function:<br>
return n * factorial(n-1)  


Take the time to prepare some coding questions. Sometimes users may not understand your questions. Don't be so quick to jump the gun and assume they don't know the answer. Give them a chance to explain themselves.

Find Out More

Most of us appreciate when a candidate just admits to not knowing the answer to your questions, but sometimes it's not that simple. Sometimes they may know about the question or something related. Prepare enough interview material so you can jump over stuff that they can't answer. Avoid taking a lot of time waiting for them to answer a question that you believe to be simple, there may be other knowledge they have that is yet to be uncovered.

Tag cloud