I wanted to talk a little bit today about the Rest Parameter and Spread Operator in JavaScript. When I first learned JavaScript, I knew where to use these these, but I didn’t really fully grasp the concepts behind them, so I thought it might be useful to you, to go through them a bit.

Rest Parameter

The rest parameter is shown by ... (three periods) and according to MDN, “The rest parameter syntax allows a function to accept an indefinite number of arguments as an array…”. In other words, it gives us a way to give a function any number of arguments…


In internet terms, a Cookie is a small text file that is saved on a user’s computer, in order to, allow an otherwise stateless (or memory-less) HTTP communication to pretend to have a state. In simpler terms, a cookie saved information about a website that you visit so that when you leave the website and come back it kind of “remembers” you. In this article I wanted to just do a simple run through of how to manipulate cookies with JavaScript. Cookies are saved in key=value pairs, so you might see a simplified example like…

username=joethecat99

…when a user logs…


In JavaScript a Prototype is, basically, the blueprint to build an object. According to MDN, “Prototypes are the mechanism by which JavaScript objects inherit features from one another.” So, Array Objects inherit their properties from the Array Prototype, Math Objects inherit their properties from the Math Prototype, and every prototype inherits their methods and properties from the Object Prototype. Let’s use an example to get a better look at this…

function Person(name, age, hometown){
this.name = name;
this.age = age;
this.hometown = hometown
};

Here we are just using a function to create a Person object for us, that will…


In my continuing search of interesting JavaScript topics, I today bring you two functions, call() and apply(). Basically, these two function have one purpose to call a function and define what the value of this is. Let’s take a look at an example to show what we need call() and apply() for…

let guest1 = { name: "Bob", age: 35, hometown: "New York" };
let guest2 = { name: "Mike", age: 23, hometown: "Chicago" };
function sayHi(){
return console.log("Hi, " + this.name + "!");
};
function sayBye(){
return console.log("Bye, " + this.name + "!");
};
sayHi(); // Outputs Hi, undefined…


In JavaScript, Object Destructuring is defined by MDN as a “JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.” The idea here is that by using object destructuring we can take the elements of an array or object and give them their own variables. Now this sounds pretty much like just trying to access the property of an object by assigning it to a variable, but it gives us a little bit of a time saver. …


Credit: Clément Hélardot

Memoization is defined as “is an optimization technique used primarily to speed up computer programs by storing the results of expensive function calls and returning the cached result when the same inputs occur again”. To break this down, basically, what we want to do with memoization is try to speed up expensive function calls by caching previous results from the execution of the function call so that we are not performing the same calculations or operations over and over again.

Let’s take a look at a simple example, to start…

function addTo768(number) {
return number + 768;
}
addTo768(10); //…


I’ve spend a couple of articles talking about falsy values in JavaScript (if you’re interested…NaN and Null and Undefined), and I wanted to turn things around and talk about truthy values in JavaScript.

To recap my previous articles, in JavaScript there are six values that are considered to be falsy, and they are false, 0, ‘’, null, undefined, and NaN. Now if you have, basically, any other value than one of these six, then there’s a good chance that value will be truthy. Now this does not mean that the value itself is equal to true but that when the…


null and undefined are two of the six falsy values in JavaScript, the others being false, 0, ‘’, and NaN (I talked about NaN here). Now null and undefined are similar but…different, we’re going to talk about why.

Null

null, according to MDN, “represents the intentional absence of any object value.” Which is basically saying that null represents an empty value or nothing, we could have also explicitly set a value to null, as such…

let nothingHere = "Nothing";nothingHere = null; // Removes "Nothing" and sets nothingHere to
null
nothingHere === null; // Outputs true

That’s pretty much it for…


NaN or Not A Number can cause issues when you’re trying to pay your gas bill.

In JavaScript, the number type can be either an integer or a float, as such…

let integer = 10;let float = 10.5;typeof(integer) // Outputs numbertypeof(float) // Outputs number

Now, NaN stands for “Not A Number”, and it means, well, whatever you’re looking at is not a number, that being said we can’t do something like…

let example = 'banana';typeof(whatever) // Outputs string

Because even though our example variable is not a number, it is still a valid data type and JavaScript tells us what that type is. However, if we did something like this…

let example…


An interesting and seemingly menacing sounding topic in JavaScript is the Temporal Dead Zone. Essentially, the Temporal Dead Zone refers to a behavior in JavaScript when variables are declared with the let and const keywords, and the space between where a variable enters scope and where it can be accessed is the Temporal Dead Zone. Let’s take a look at normal behavior for variable declaration…

let example = 10;
console.log(example); // Outputs 10

However, if we try to reverse the order…

console.log(example);
let example = 10; // ReferenceError: Cannot access 'example' before
initialization

In this example our console.log(example) is in…

Chris Hosler

Computer Support Tech turned Software Developer

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