I’m going to take a guess that you’re here because you recently got an interview for a JavaScript job. Am I right?
If this is the case, first of all, don’t worry. We’re going to walk through exactly how you should spend your time to give yourself the best shot at success.
How To Organize Your JavaScript Interview Preparation
Every interview process is different—companies hire in different ways because of time constraints, the separation of human resources and tech departments, and general confusion on what makes a good developer and what type of developer is required. Throw into the mix that evaluating technical competence is incredibly difficult and the result is widely varying interview methods.
As a result, hiring processes can vary widely between companies. But no matter where you’re interviewing, you can build a solid foundation of knowledge to give you the best chance at success—and we’ve compiled that foundation in this post.
Most interview processes for JavaScript positions have a couple of phases:
Phase 1) The initial phase is usually comprised of simple, short questions intended to quickly sift through the first set of candidates. This stage looks like (what is often deemed) “trivia,” as it can be crude, simplistic questions about core language concepts. While many in the industry are opposed to this type of interview testing, it’s still quite a common practice. So, like it or not, you may face this hurdle first, so you should be prepared.
Phase 2) After the initial phase, you’ll likely be invited on-site for a more thorough technical interview. This can often look like answering questions along the lines of “explain this code” or “implement this in code.” These questions are usually tricky combinations of various concepts in the JavaScript language, combining concepts like closures, scoping, functional programming, and the works.
In this article, we’ll cover just the first phase, broken down into the following sections:
- Core JavaScript—The central parts of the JavaScript language
- Programming Paradigms/Patterns—Design patterns, object-oriented programming (OOP) versus functional, etc.
- Scope and Closures—How JavaScript manages scope
- Types, Grammar, and Syntax—The more fiddly bits of the language
- Asynchronous (async) and Performance—How to tune JavaScript
With these categories under your belt, you’ll be very prepared for your JavaScript interview.
Preparation Approach
Before we move on to the code, I want to quickly mention what type of mindset to take on before you start diving into the prep work for your JavaScript interview. If you don’t take a step back to remember what’s important throughout the process, it’s very easy to fall into various traps, such as memorizing the wrong areas and generally working yourself up with frustration.
Let’s take a look:
- Take Your Time—We’re going to cover a lot of ground in this post. Don’t try to take it and digest all the information here at once. It will take time, so pace yourself.
- Experiment in Code—Trying out code is the best way to gain an understanding of an unfamiliar concept.
- Focus on Your Weaknesses—Scan through the list of questions, make a note to yourself next to the concepts you are not familiar with, and consider starting there.
- This Isn’t a Memory Test—Programmers have access to the internet and interviewers know this. Don’t try and simply memorize minutia, like every helper function.
- Focus on Concepts over Details—Just as you shouldn’t try and memorize this list, you also should focus on concepts rather than details. For instance, learn what a map function does conceptually; don’t agonize over the ordering of the properties that are passed in.
- Vary Your Media—Try swapping media to break monotony while preparing. Practical coding, talking through with a friend, or using flash cards are good alternatives to reading, but really diving in and experimenting is your best bet.
- Answer Out Loud Before Reading the Answer—It might be tempting to just jump to the answer here, but resist this urge. Instead, read the question out loud to yourself and practice saying the answer to your prospective employer.
- Don’t Forget Other Research—This is an article about JavaScript, but the technical parts aren’t the only areas to prep for. Spend time learning about the business you’re interviewing at, and practice presenting or any other skills/knowledge you’ll need for the interview.
Part 1: Core Concepts
Category: Core JavaScript
In this section we’ll go through some of the fundamentals of the JavaScript language. These are questions related to the language itself rather than the syntax.
1) What does single-threaded mean and why is it important for JavaScript?
Hint: It is related to asynchronous behavior.
2) Name three different ways to define variables in JavaScript and explain how they differ.
Hint: It has to do with scoping and mutability.
3) What is short-circuit evaluation and why does it matter?
Hint: It has to do with logical operators (AND, OR, NOT).
4) What is blocking in JavaScript and why is it important?
Hint: It’s related to performance.
5) What is node.js and how does it differ from JavaScript in a browser?
Hint: Not all methods and functions belong to JavaScript itself.
6) What is immutability?
Hint: It has to do with the ability to change data.
Category: Programming Paradigms
JavaScript as a language takes inspiration from many others, including Java and C. This means there are elements of different paradigms available to the language. Therefore, it is important that a JavaScript developer knows what these different paradigms are, why they’re important, and when to use each one.
7) What is “pass by reference” versus “pass by value”?
Hint: It’s about object creation.
8) What are the two main programming paradigms that are important in JavaScript?
Hint: One is about ideas of inheritance, the other about composition.
9) What is functional programming?
Hint: The clue is in the name.
10) What are the main ideas behind OOP?
Hint: Think about how code is shared.
11) What are the pros and cons of functional programming versus OOP?
Hint: Think about shared state, side effects, and simplicity.
12) What is the difference between class and prototypal inheritance?
Hint: Think of how objects can be replicated.
13) What does the this keyword refer to in JavaScript?
Hint: Think about how functions are called.
14) What is a “recursive” function?
Hint: It allows us to iterate through a function even if we don’t know how many loops we’d need.
Category: Scope and Closures
Closely linked to scope in JavaScript is the idea of a closure. While obtuse in its name, once you wrap your head around the concept, you’ll be writing elegant JavaScript. However, it’s not without its drawbacks. You’ll want to understand both the pros and cons of the JavaScript closure.
15) What is a closure?
Hint: A closure is a concept closely related to scope in JavaScript.
16) What is hoisting in JavaScript and what does it mean?
Hint: It’s not about what is declared, but when.
17) What is lexical scope?
Hint: It has to do with how values are accessed and the compiled nature of JavaScript.
18) What is an immediately invoked function expression (often referred to as IIFE) and why is it important?
Hint: Think about scoping and how JavaScript scopes.
19) What is currying?
Hint: It relates to functions and how they can be used to encapsulate scope.
Category: Types, Grammar, and Syntax
In this section, we’ll cover the more fine-grained details of the language. Syntax is important, as it will define the way different code functions. For instance, it’s easy to dismiss the difference between a template literal and a regular string; it’s a subtle difference in syntax, but it has large functional differences.
20) What is the benefit of the “use strict” declaration in JavaScript?
Hint: It is related to backward compatibility.
21) In ECMAScript 2015 and later, what is object destructuring?
Hint: It has to do with how we assign values to our scope from objects.
22) What is an interpolated expression (template string)?
Hint: It has to do with mixing strings and variables together.
Category: Asynchronous Programming and Performance
JavaScript is a single-threaded language, which means that it can process only a single piece at a time. This means in order for JavaScript to run fast, it needs to ensure that nothing is “blocking” it from processing other code. JavaScript has a number of different ways to handle asynchronous code.
23) What is asynchronous programming and why is it important in JavaScript?
Hint: It has to do with the single-threaded environment.
24) What is the event-loop in JavaScript and why is it important?
Hint: It’s related to how code is loaded and the single-threaded nature of JavaScript.
25) What is a promise?
Hint: Think about the single-threaded nature of JavaScript.
26) What is a memory leak?
Hint: When the language cannot release memory, it causes this issue.
27) How could you cause a JavaScript memory leak?
Hint: There are a few answers … consider concepts like scoping, Document Object Model (DOM), and closures.
28) What are the async/await keyword(s) and what are their advantages and disadvantages?
Hint: It has to do with how you can write asynchronous code.
Category: Functions
Functions are debatably the most important part of the JavaScript language and are at the heart of the versatility of JavaScript. Functions encapsulate behavior, and when combined with the ability to pass functions to functions, return them from functions, etc., this results in some very concise and readable code.
29) What is a pure function?
Hint: It’s related to side effects.
30) What is a function “prototype”?
Hint: It’s related to how functions share behaviors.
31) What are the advantages/disadvantages of using a functional iteration method when compared with a “for loop”?
Hint: It has to do with scoping.
32) How do you set a default parameter value for a function?
Hint: There are three ways to do this: one with ES5 syntax, one with ES6.
33) What is the difference between a function and a method?
Hint: Function is declaration.
34) What are the different ways to define a function?
Hint: Think about classes and variable assignment.
35) What is a “fat arrow” function?
Hint: Think about the function definition.
36) When would you use a fat arrow function?
Hint: Think about where using a fat arrow could be bad.
37) Explain the functional methods for arrays in JavaScript.
Hint: Typically, they are used to make arrays shorter (in different ways).
38) What is the difference between .call, .bind, and .apply?
Hint: They all relate to the this keyword; the difference is in how they’re used.
39) What is a debounce/throttled function?
Hint: Debounce is used for performance reasons.
Wrap-Up
Phew! That was a lot of trivia! One of the best ways to ensure that your knowledge has sunk in is to prepare with a partner or friend or write down the answers to the questions as you go.
Remember: An interview isn’t just about your technical ability, but other skills, like your attitude, communication, and cultural fit as well. So you likely don’t need to be a published author on JavaScript, but have a foundational knowledge and a hunger to learn.
Good luck!