Preparing for a JavaScript developer interview? Here's a guide to the top 10 questions you might face. Master these, and you'll be one step closer to landing that dream job.
Update: 2020
Thanks in part to warnings from influential software developers and framework authors, the trend of overusing class inheritance in JavaScript has mostly died.
- In recent job interviews, ask the candidate to build a click counter using any popular framework (React preferred in 2020).
- The goal is to verify that they know how to code.
What is functional programming?
Functional programming produces programs by composing mathematical functions and avoids shared state & mutable data.
- Good to hear: Pure functions / function purity
- Avoid side-effects
- Simple function composition
- Examples of functional languages: Lisp, ML, Haskell, Erlang, Clojure, Elm, F Sharp, OCaml, etc…
- Red flags: No mention of pure functions/function purity, inability to provide examples of functional programming languages, and inability to identify the features of JavaScript that enable FP
Cons: Objects and behaviors are typically tacked together on the same entity, which may be accessed at random by any number of functions with non-deterministic order.
Over exploitation of FP features such as point-free style and large compositions can potentially reduce readability because the resulting code is often more abstractly specified, more terse, and less concrete.
- A highly functional codebase can have a steep learning curve.
What are Two-way Data Binding and One-Way Data Flow?
Two way data binding: UI fields are bound to model data dynamically such that when a UI field changes, the model data changes with it and vice-versa
- One way data flow: Changes in UI trigger messages that signal user intent to the model
- Only the model has the access to change the app’s state
- The effect is that data always flows in a single direction, which makes it easier to understand
- Red flags: No understanding of what either one means
It Starts With People
Focus on the 3 P’s
- Senior-level candidates who can hire and mentor other developers
- Pair program with the candidate
- Watch and listen more than you talk
- See the big picture
- Syntax and features are easy to Google, but common paradigms and idioms are harder to Google
What are the pros and cons of monolithic vs microservice architectures?
Monolithic: app is written as one cohesive unit of code whose components are designed to work together, sharing the same memory space and resources
- Microservice: app consists of many smaller, independent applications capable of running in their own memory space & scaling independently from each other across potentially many separate machines
- Pros: better organized, easier to recompose & reconfigure to serve the purposes of different apps
- Cons: too tightly coupled & difficult to isolate services for purposes such as independent scaling & code maintainability
- Red flags: Unaware of the differences between monolithic & microservice architecture, Unaware or impractical about the additional overhead of microservices, and Too negative about the drawbacks
Two programming paradigms that are important for JavaScript app developers
Prototypal inheritance
What does “favor object composition over class inheritance” mean?
It means that code reuse should be achieved by assembling smaller units of functionality into new objects instead of inheriting from classes and creating object taxonomies.
- Avoid class hierarchies, avoid brittle base class problem, avoid tight coupling, and make code more flexible.
- Red Flags: Fail to mention any of the problems above, and fail to articulate the difference between composition and class inheritance.
What is asynchronous programming and why is it important in JavaScript?
Asynchronous programming means that, barring conditionals and function calls, code is executed sequentially from top-to-bottom, blocking on long-running tasks such as network requests and disk I/O.
- Node is asynchronous by default, meaning the server works in much the same way.
Conclusion
Stick to high-level topics
- If they can answer these questions, that typically means that they have enough programming experience to pick up language quirks & syntax in a few weeks
- Don’t disqualify candidates based on stuff that’s easy to learn
What is the difference between classical inheritance and prototypal inheritance?
Class Inheritance: instances inherit from classes, and create sub-class relationships: hierarchical class taxonomies. Instances are typically instantiated via constructor functions with the new keyword.
- Prototypal Inheritance : instances inherit directly from other objects, typically via factory functions or Object.create(). Instances may be composed from many different objects, allowing for easy selective inheritance.
When is classical inheritance an appropriate choice?
Rarely, almost never, or never.
- A single level is sometimes OK, from a framework base-class such as React.Component. A.k.a. “Favor object composition over class inheritance.”
When is prototypal inheritance an appropriate choice?
Delegation
- Concatenative
- Functional
- Any time you need inheritance
- Red flags: No knowledge of when to use prototypes. No awareness of mixins or Object.assign().