Javascript Interview Questions Cheatsheet 2019/2020

Going through a company hiring process is hard. Many stages of interviews, questions and meetings have to be made before the two parts can make a common decision. However, in all of these stages, we can identify one that is extremely important. This will decide whether or not you will be hired, and that is the technical interview.

Now, if you are like many developers out there, trying to get into the constantly growing world of web development, you will have to know Javascript for sure. And that is probably what most of the interview is going to be about. A senior developer or technical director of the project will ask you questions to validate your knowledge in the field.

This guide is a quick refresher you can use before any Javascript related interview session. Whether you will be home or on the train directed toward the office, the purpose of this article is to help you to better prepare yourself and be a recap before any interview.

#1 What is the difference between var and let?

Back to the pre-ES6 days, there wasn’t much choice concerning how you would define a variable in Javascript. The var keyword has been an easy standard for years but now things have drastically changed. ES6 has, in fact, brought to use a very desired functionality introduced by the new keyword let. 

“The difference between var and let is that var is function scoped while let is block-scoped”

This paradigm is already extremely common in other languages, let’s see a quick example of how it works practically.

difference between var and let

As you can see from the above example, since let is block-scoped, defining action inside our curly braces doesn’t interfere at all with the action variable outside of the block.

#2 Explain the difference between == and ===

The difference between these operators is that:

The ”==” operator performs a test based on abstract equality ( the necessary type conversions before doing the equality comparison is applied).

While the “===” operator tests for strict equality (no type conversion is applied, meaning that if two values are not of the same type when compared, the operator will return false).

difference between equals operator

In particular, you have to remember

  • Two strings are strictly equal when they have the same sequence of characters, same length, and same characters in corresponding positions.
  • Two numbers are strictly equal when they are numerically equal (have the same number value). NaN is not equal to anything, including NaN. Positive and negative zeros are equal to one another.
  • Two Boolean operands are strictly equal if both are true or both are false.
  • Two objects are strictly equal if they refer to the same Object.
  • Null and Undefined types are == (but not ===). [I.e. (Null==Undefined) is true but (Null===Undefined) is false]

#3 Why do we place “use strict” at the beginning of a Javascript file?

The “strict mode” is a feature that was born with ECMAScript 5, it allows you to put your application into an operating context that is “strict”. Practically this means that certain operations that are considered to be unsafe will be rejected and errors will be thrown. Benefits of using this mode include:

  • Prevents unsafe actions to be performed
  • Makes writing safer code easier
  • Prohibits some syntax likely that is probably going to be implemented as a part of future versions of the language.

#4 What is a callback?

A callback is a function that will be executed after another function has finished executing “. Callback functions are great whenever you have to perform some operations after another one has been completed. For example, if you want to print some data after an API request has been completed.

what is a callback

#5 What is a closure?

A closure is simply an inner function that has access to the variables in the enclosing outer function’s scope. So a closure will have access to three particular scopes:

  • The variables in its own scope
  • The global variables
  • The variable in the enclosing function’s scope

#6 What is a pure function?

To be considered pure, a function has to pass the following tests:

  • It always returns the same result if the same arguments are passed in. And It does not depend on any state, or data, change during a program’s execution. It must only depend on its input arguments.
  • It doesn’t produce any observable side effects (network requests, data mutation).

what is a pure function

Using pure functions come with many benefits including:

  • Easier and immediate testing: since they will always produce the same results if you pass in the same arguments.
  • Easier maintenance: change a pure function and just don’t worry about any possible side effects caused by changing variables values.

#7 What is a promise

A Promise is an object representing the eventual completion or failure of an asynchronous operation. In substance, a promise is a returned object to which you attach callbacks, instead of passing callbacks into a function. So with them, instead of writing old school callback functions like this:

what is a promise

you would write something like:

what is a promise second example

#8 What is functional programming

Functional programming is a development paradigm, which means that it’s a way of thinking and structuring our code based on certain rules and fundamentals. It is a declarative paradigm rather than an imperative one, where the state of our application flows through our pure functions instead of being shared with methods belonging to objects. The basics structures of this paradigm are:

  • Pure functions
  • Function composition
  • Avoiding shared state
  • Avoiding mutating state
  • Avoiding causing side effects

#9 What is function composition

In Javascript, function composition is a mechanism used to combine multiple simple functions in order to build a more complicated one. In this mechanism, the result of each function is passed to the next one to perform certain operations. An example of this can be when performing a simple operation such as 2 + 6 / 3.  In this case, we know that division should take precedence over addition, and so we can make use of function composition to first process this operation and then perform addition:

what is function composition

#10 Describe what is the difference between classical inheritance and prototypal inheritance?

Class Inheritance: instances inherit from classes (which provides a scaffolding for its instances), and create sub-class relationships. Instances are typically instantiated via constructor functions with the new keyword.

Prototypal Inheritance: in this case instances inherit directly from other objects. They are typically instantiated via factory methods or Object.create().


I hope this article was helpful as a quick refresher for you in order to be better prepared for your next interview and, possibly, land that dream job. Continue to follow CodeWall for more articles like this!

Leave a Reply