Jennifer Bland header image
≡ Menu

Understanding Closure in JavaScript

A closure is a function object that retains ongoing access to the variables of the context it was created in (even after the outer function calls it was created within have returned).

In other words, the function defined in the closure ‘remembers’ the environment in which it was created.

Let me give you an example:

function getName()
  var firstName = 'Jennifer';
  function showName()
    alert(firstName);
  }
  showName();
}
getName();

[continue reading…]

Hack Reactor Week 3 Review

After completing my 3rd week, I realized that I am one quarter of the way through my training at Hack Reactor. Unofficially next week I will have graduated from a Freshman to a Sophomore.

Week 3 is historically considered the hardest week at Hack Reactor. After just completing that week I can agree whole heartedly with that assessment.

Monday of Week 3 started with our self-assessment. We are giving a short time period to complete an assessment that tests our knowledge of the material covered in the previous week.

Our assessment this week was to:

  • Rewrite a function declaration into pseudo-classical
  • Write a function to find duplicate characters
  • Utilized several D3 functions
  • Describe time complexity of several algorithms

[continue reading…]

How Hoisting in JavaScript Can Cause Unexpected Results

Your can experience unexpected results in your JavaScript programs due to execution that does not occur like you expected. A good example of this is that you can actually use a variable in JavaScript before you declare it. Here is an example:

x = "Jennifer";
for (var i = 0; i < 10; i++) {
  console.log(i);
}

var x;

JavaScript allows this code to function due to a concept known as "hoisting." Hoisting the default behavior of a JavaScript application once it executes.

Within the current scope in a JavaScript application, all variables are "hoisted" to the top regardless of where they are declared.

[continue reading…]

Breadth First Search in JavaScript

In my previous post I discussed the difference between a graph data structure and a tree data structure. Now that you understand the difference between the two data structures, I am going to show you how you can search through your data.

The two most common methods of searching a graph or a tree are depth first search and breadth first search.

Whether to use a depth first search or a breadth first search should be determined by the type of data that is contained in your tree or graph data structure.

[continue reading…]

The Difference Between a Tree and a Graph Data Structure

In JavaScript programming, data can be stored in data structures like graphs and trees. Technically trees are graphs.

Graphs Data Structures

Graphs evolved from the field of mathematics. They are primarily used to describe a model that shows the route from one location to another location.

A graph consists of a set of nodes and a set of edges. An edge is a pair of nodes that are connected. A path is the term used to describe traveling between nodes that share an edge. The image below shows a graph with 3 nods and 3 edges.

graph data structure with 3 nodes and 3 edges

 

[continue reading…]