What are Closures in JavaScript?

Closures in JavaScript refer to a function's lexical scope and the retained reference and state of variables and functions within that scope. This provides the ability to access an instance of a function and it’s scope (and so access it’s scoped variables and functions that were available at the time of creation) from outside of the original scope.

Read more

What is Hoisting in JavaScript?

When your JavaScript is being compiled, variables and function definitions are made available to the JavaScript engine. When the engine executes your code, the declared vars and functions from the compilation phase are made available before the value assignments, irrespective of the order in which they were written. This can be envisaged as “hoisting” the declarations to the top of the current scope.

Read more

What is Lexical Scope in JavaScript?

Lexical scope is the set of rules for how the JavaScript engine finds variables and functions when executing code, relative to where you've defined them at author-time. The “lexical” refers to the lexing phase of compilation which takes place before code execution. This is in contrast to dynamic scope where the rules of scope can be generated dynamically, while the code is executing at runtime.

Read more

IIFE JavaScript Example

An IIFE stands for immediately invoked function expression. I’ve also heard the term self invoked anonymous function (SIAF), but IIFE encompasses the pattern with a named function too.

Here’s the code for those that want a quick copy-and-go, but we’ll run through it underneath for those who want to understand the syntax 🍻.

Read more

What's ReferenceError: x is not defined in JavaScript?

The ReferenceError is an error thrown by the JavaScript engine when it looks to find a variable or function within the available scope and finds nothing with that identifier name. The error will be thrown if you're trying to assign a value to an undeclared variable, or access the value of an undeclared variable.

Read more
Back home