How hide your variables

The literal definition of closure would be “an act or process of closing something.” We can use this definition to try to understand code closures as well. What we’re going to be doing is “closing” off a variable to make it inaccessible to anyone unless we call a function.

Using a simple closure

The following is an example of a closure in JavaScript:

function closureTest() {
let i = 1;
return function() {
console.log(`the counter is ${i}`);
i += 1;
}
}

Great! We have a function that returns …another function? What exactly does this do? Well, in short, we basically made the variable…


When it comes to understanding if something is being passed by value or by reference, it can easily get confusing. In this small writing, I will try to explain what it means as best as possible so that maybe you can learn the way I did.

First thing’s first, we have to understand what it is that a variable is being assigned to. From a beginner’s standpoint, we know that when you declare a variable, we are telling the computer to make some space in the memory to hold a certain value. For example, let’s say that we have a…

Ricardo Villarreal

Aspiring to be a software engineer and always willing to help and learn!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store