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

Using Prism.js in a Next.js site

I'm using Prism.js to style the code blocks on Frendly, but when I was setting it up I couldn't find official docs for adding Prism.js to a Next.js site (which Frendly is built with). Here's how I managed to get things working.

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

A HTML Post

This post is currently being written! It's a placeholder while Frendly is in being designed. More coming soon...

Read more