Skip to content

Instantly share code, notes, and snippets.

@markreid
Created October 22, 2015 06:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markreid/aa2891f6fad5811f8c07 to your computer and use it in GitHub Desktop.
Save markreid/aa2891f6fad5811f8c07 to your computer and use it in GitHub Desktop.
JS Dev Interviewee quiz

JS Dev quiz.

Most of these questions have several possible answers and no real wrong answer. The aim of the quiz is to gauge your level of experience with software development in general but also your experience working directly in Javascript, so add as much detail as possible, explain how you arrived at your answer, etc.

Some of the questions are quite difficult or confusing, so don't worry too much if you're not sure about the answers; a couple of them are deliberately designed to be hard to solve!

General questions

  1. Describe the stack for a recent project that you found interesting.
  2. What were the pros and cons of this stack and how did you deal with some of the challenges?
  3. Have you got experience working in a production team? Briefly describe the team structure and your role in it.
  4. Have you used any ES6/ES2015 features? What are your favourites, and how have they improved your code?
  5. Explain how linting and Strict Mode can help improve your code.
  6. Do you write your JS as modules? Which system (AMD/CommonJS/ES2015 etc) do you prefer, and why?
  7. What's the difference between two-way data binding and unidirectional data flow?
  8. Briefly outline a best-practices testing strategy, explaining why testing is or isn't useful.
  9. Have you ever pushed a serious bug into production? What steps did you take to ensure it wouldn't happen again?
  10. What patterns/practices do you use in relation to version control?

Code Questions

/**
 * appends the string 'World' to the value of `this`
 * @param  {String} str
 * @return {String}
 */
function appendWorldToThis(){
    return this + 'World';
}
  1. Call the function above so that it returns 'Hello World'.
/**
 * Asynchronously double `value` or return an error.
 * `callback` argument should comply with node-style "error-first" signature
 * @param  {Number}   value
 * @param  {Function} callback
 */
function makeAsyncCall(value, callback){
    setTimeout(function(){
        if(Math.random() > 0.5){
            callback('ERROR');
        } else {
            callback(null, value * 2);
        }
    }, 1000);
}
  1. The function above can be described as "asynchronous". What does this mean?

  2. "Error-first" is a common pattern for functions in Node; what purpose does it serve?

  3. Write a wrapper for makeAsyncCall that returns a Promise (use ES2015 Promise spec or your favourite Promise shim/library)

makeAsyncCall(500, function(error, data){
    if(error){
        console.error(error);
    } else {
        console.log(data);
    }
});
  1. Call your promisified makeAsyncCall wrapper so it has the same outcomes as the code above.

  2. What are some advantages of using Promises?

  3. What are some advantages of using Callbacks?

function aggregateArguments(){

}
  1. Compose the aggregateArguments function such that it takes an arbitrary number of arguments and returns an object where:
  • The object keys are the unique arguments
  • The values are the number of times those arguments each occur

eg:

assert.equal(aggregateArguments('foo', 'bar', 'qux', 'foo', 'bar', 'foo'), {
    foo: 3,
    bar: 2,
    qux: 1
});

Observe the following:

for(var i=0; i<5; i++){
    setTimeout(function(){
        console.log(i);
    }, 0);
}

Running this code will print the value 5 to the console five times.

  1. Why doesn't it print 0, 1, 2, 3, 4?

  2. Without removing the setTimeout, modify the code so it does print 0, 1, 2, 3, 4

/**
 * Mystery function
 * @param  {Object[]} a
 * @param  {String} b
 * @param  {String} c 
 * @return ???
 */
function mystery(a, b, c){
    return a.reduce(function(d, e){
        d[e[b]] = e[c];
        return d;
    }, {});
}
  1. What is the type of a?

  2. What does this function do, and what might it be useful for?

  3. Provide a set of arguments (of valid type) that would break the intended functionality, and explain why. Suggest how you could guard against that.

  4. What would be the disadvantages of using the code snippet above in production code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment