Show Menu

JS interview Cheat Sheet by


Function body has access to variables defined outside its scope
Closure is when a function is able to remember and access its lexical scope even when that function is executing outside its lexical scope.
Useful in callbacks. For example passing a value into an ajax success. Var can be defined before the call and still accessed from the success

Higher order funtions

Functions that accept other functions as their arguments.
EG .map or .filter
Can help to write code quicker with less bugs due to code reuse


When a function calls its self until it doesn't
An example would be when you have a bunch categories form a DB and you want to map all the children into a tree structure.


Break and object or array into variables
Great for options objects like ajax options
Can be put into the function declar­ation params with optional values

Prototypal Inheri­tance

Objects inherit directly from other objects.
Instances may be composed from many different source objects, allowing for easy selective inheri­tance and a flat [[Prot­otype]] delegation hierarchy.
The tight coupling problem, Inflexible hierarchy problem
The Gorill­a/b­anana problem (What you wanted was a banana, but what you got was a gorilla holding the banana, and the entire jungle)

Factory functions

Factories - Functions that create objects and return them.
Better to use than classes for Compos­ition!
Inheri­tance encourages you to predict the future of your classes (bad) it will most likely change though out the project


Compos­ition is simply when a class is composed of other classes; or to say it another way, an instance of an object has references to instances of other objects.
Is better as we dont have to think of all our classes at the start and when we inevitably need to change them we can with ease
Eg A robot dog needs the bark from the dog class but not the sleep.


Currying is when a function, instead of taking all arguments at one time, takes the first one and returns a new function that takes the second one and returns a new function which takes the third one, and so forth, until all arguments have been fulfilled.
The idea is that a function can pass through an applic­ation and gradually receive the parameters it needs

Two types of function

Declar­ation -
function something (){}
Hoisted to the global scope
Expression -
 var something = function (){}
Good to use for passing function into other function. EG the ajax success or a .map


Objects can be thought of as the main actors­(th­ings) in an applic­ation
Every component in JavaScript is an Object, including Functions, Strings, and Numbers
We normally use object literals or constr­uctor functions to create objects.


Refers to enclosing all the functi­ona­lities of an object within that object so that the object’s internal workings (its methods and proper­ties) are hidden from the rest of the applic­ation.
This allows us to abstract or localize specific set of functi­ona­lities on objects.
A way to do this would be wrap everything in an Immedi­ate­ly-­Invoked Function Expression IIFE - a way to implement the module pattern. Allows private methods and data, defining an API for public use.

OO Javascript

(OOP) refers to using self-c­ont­ained pieces of code to develop applic­ations
Building applic­ations with objects allows us to adopt some valuable techni­ques, namely, Inheri­tance


refers to an object being able to inherit methods and properties from a parent object


Uses a Uni-di­rec­tional data flow to keep a Single source of truth
The state of your whole applic­ation is stored in an object tree within a single store.
State is read-only. The only way to change the state is to emit an action, an object describing what happened.
State tree is transf­ormed by actions, written with pure reducers.


No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          AngularJS Cheat Sheet
          JavaScript Cheat Sheet
          Web Programming Cheat Sheet