JavaScript in 30 words
Browse all 35 concepts

Pre interview prep

JavaScript concepts in 30 words or fewer, with code to make them stick. Pick a topic to get started.

Fundamentals

Variables

Variables can be denoted with the keywords let or const. The accepted convention is to use const as much as possible, and let when the variable is likely to be re-assigned

Functions

Functions in Javascript consist of the function keyword followed by the name of the function, a list of parameters and statements that define the function.

Function Expressions

Functional expressions load only when the interpreter reaches that line of code. They're not hoisted, allowing them to retain a copy of the local variables from the scope where they were defined. They do not polute the global scope.

Operators

  • + Addition
  • - Subtraction
  • * Multiply
  • / Divide
  • % Modulus
  • ++ Increment
  • -- Decrement

Comparisons

  • == Equal to
  • === Equal to Value and Type
  • != Not Equal
  • !== Not Equal in Value or Type
  • > Greater
  • < Smaller

Conditional (Ternary) Operator

The condition is evaluated as a boolean. If the condition is true it returns the first expression, else it returns the second condition.

For Loops

A for loop creates a loop with three optional expressions; enclosed in parentheses and separated by semicolons, followed by a statement (usually a block statement) to be executed within the loop.

While Loops

A while loop loops through a block of code "while" the condition is true.

Switch Statements

A switch statement is an alternative to multiple if statements. Switch statements are a more efficient way to code when testing multiple conditions.

Arrow Functions

A concise syntax for creating functions. If we have only one argument, then parentheses around parameters can be omitted. Arrow functions do not have a 'this' context.

Array Methods

  • forEach() - loop over array's items
  • map() - new array by calling the provided function in every element
  • filter() - new array with only elements that pass the condition

String Methods

  • concat() Combines strings
  • indexOf() returns index of character
  • match() matches based on REGEXP
  • slice() Returns a substring based on the “start” and “end” parameters
  • split() Splits a string according to the specified delimiter

Classes

ES6 syntactic sugar that allows us to program in a more object-orientated way. It allows us to define a constructor together with its prototype methods.

Scope

Scope refers to the current context of code, which determines the accessibility of variables to JavaScript.

Advanced

The call stack

A Call Stack is a data structure that stores and manages function invocations. A kind of 'To-do list' for Javascript that uses the Last In, First Out (LIFO) principle.

Event loop

The Event Loop monitors the Call Stack and the Callback Queue. If the Call Stack is empty, it pushes the first event from the queue to the Call Stack.

IIFEs

An IIFE (Immediately Invoked Function Expression) is a JavaScript function that runs as soon as it is defined. Variables declared inside the IIFE have private scope.

Nested functions

A function within another function. A nested function can 'inherit' the arguments and variables of its containing function. Put simply; the inner function contains the scope of the outer function.

Recursion

Recursion is a technique for iterating over an operation by having a function call itself repeatedly until it arrives at a result. Most loops can be rewritten recursively.

Memoization

Memoization is the programmatic practice of making recursive/iterative functions run faster by caching the values that the function returns after its initial execution.

Closures

The combination of a function and the environment in which it was declared. In Javascript all functions form closures. A common use case is creating private functions.

Hoisting

Hoisting is a JavaScript mechanism where variables and function declarations are moved to the top of their scope before code execution.

Currying

Currying is the process of transferring a function with many arguments into the same function with fewer arguments. Allowing you to partially apply functions and pass them to higher-order functions.

Value vs reference

Pass by value means the actual value is passed on. Pass by reference means a number (where the value is stored in memory) is passed on.

Asynchronous JavaScript

Javascript is a single-threaded language. Meaning it performs one action at a time. Asynchronous Javascript is a way to perform multiple actions simultaneously using callbacks, promises, and async/await.

Promises

A promise is an object that may produce a value sometime in the future. Either a resolved value or a reason that it’s not resolved (e.g., a network error occurred).

Async and await

Async/Await is syntactic sugar that makes promises easier to work with. It allows us to write asynchronous code that's similar in appearance to synchronous code.

Global objects

A Global Object is an object that always exists in the global scope. In a browser, the Global Object is the 'Window' and in Node.js the object is Global.

this keyword

The “this” keyword allows you to decide which object should be focal when invoking a function or a method; effectively allowing you to reuse functions with different contexts.

call()

With call you can write a method once, and then inherit it in another object, without having to rewrite the method for the new object.

apply()

The only difference between apply() and call() is that the second parameter of the apply() method accepts the arguments to the actual function as an array.

bind()

Similar to call and apply except bind() returns a function instead of a value. It sets the value of 'this' and returns a function. It does not invoke the function.

Prototypal inheritance

Inheritance is simply one object trying to inherit properties and methods of another object. A prototype is simply an object with inbuilt methods that are attached to your object.

Polymorphism

Polymorphism Is the practice of designing objects to share behaviors and to be able to override shared behaviors with specific ones. Polymorphism utilizes inheritance in order to make this happen.