notes on software

Basic JavaScript

Keywords const vs let:

const: can't reassign the variable but is mutable let: can reassign, block scoped

Closures, for loops, var, & Hoisting


// this is a pure function as it only returns the values of its inputs

function pureFun(a, b) {
  return a + b;

When we have a variable outside of a functions scope, we have a free varible we create a closure to store them in a place in memory we can access later in heap memory which keeps memory longer than in the call stack.

let b = 3;

// This function is impure as it is referencing a variable outside of its scope. It is also a closure for the same reason.

// This prevents data leakage by keeping the state inside the function to prevent leakage to the surrounding environment.

function impureFun(a) {
  return a + b

Closure: function combined with its outer state or lexical environment. We use this for data encapsulation.

What does this code log out?

for (var i = 0; i < 3; i++ ) {
const log = () => {
  setTimeout(log, 100);

Links to this note

Have anything to add? You can reach out to me by email or You can find more of my stuff on my links page.

Basic JavaScript