Author: Matt
-
JavaScript Slice and Splice
Slice in JavaScript allows you to remove items from the beginning and end of an array. The first parameter passed in to the slice function is the position of the array to start the slice operation. Remember, the first position of the array is the index 0. This position can be passed in to the…
-
JavaScript Find
If you have an array of objects and and want to find a specific object inside the array, you can use the find method to search for and return the object you’re looking for. The find method was introduced to JavaScript in ES6. The find method will return the first item that passes a test…
-
JavaScript Immutability
By default in JavaScript, variables are passed by reference. This can present some strange results. Before we look at an example, let me explain the basic concept of Mutability vs Immutability. Mutability vs Immutability Mutability simple means the ability to change. And immutability is obviously the opposite of that, not able to change. In JavaScript…
-
JavaScript Destructuring
ES6 introduced destructuring, which allows us to unpack data from arrays and objects in to their own variables. You’ll see this a lot in frameworks like React. Array Destructuring Let’s first look at examples of array destructuring. As you can see, we’ve pulled the first two values from the array in to their own variables.…
-
JavaScript Spread and Rest Operators
When I first started working with React, I started to see the spread and rest operators coming up constantly. I had not seen them before for some reason. The two operators are represented by three periods … in JavaScript code. Coming from a PHP background, I was a little confused and didn’t know what they…
-
JavaScript Template Literals
Template literals (also called template strings) allow for string interpolation of expressions using a curly brackets syntax placeholder. Template literals are defined with backticks (`) and look like this: Now if we want to see how string interpolation works, take a look at this example: You can apply any expression to a placeholder in the…
-
JavaScript Variables
The traditional way of defining variables in JavaScript was to use the var keyword. A variable assignment would look like this: In ES6, two new ways of variable assignments were introduced. They are let and const. There is a difference between var and these two new keywords though. var vs let and const The difference…
-
JavaScript Objects
Object shorthand In some circumstances, we can use the ES6 object shorthand syntax to avoid having to define object keys. Take this example for instance: Where name, email and phone are all variables. In this case we can emit the key definitions and Javascript will use the variable name as the key name. So the…
-
JavaScript Functions
Typically Javascript functions are defined as follows: Arrow Functions However, you can also use arrow functions to define functions in Javascript. Arrow functions were introduced to Javascript in ES6. A simple arrow function version of the above function looks like this: Arrow functions are anonymous functions and they must always be assigned to a variable.…