Code

General Code

Closures

When a function runs, it goes through its code, then completes. Everything goes out of scope. There are times when we might want some information to “hang around”. Let’s start by looking at an example… Within our IIFE, we have a variable (animalName). We also have a nested function that returns the animalName variable. The […]

Closures Read More »

IIFE’s

In JavaScript, we can use what are called Immediately Invoked Function Expression, or IIFEs. These are helpful for having functions run immediately when they are defined, such as when initializing an application. Let’s imagine we have the following function… Normally, we would run this function by calling it as follows… If we want to use

IIFE’s Read More »

Block Scope

JavaScript also uses block scope. When we say block, we are referring to a code block. A code block is contained within curly braces. Information is encapsulated to the curly braces within the block of code. Here is an example… Since the variable name is within the curly braces, or block of code, it is

Block Scope Read More »