Author: Matt Blanco

Last Updated: 26 December, 2021

An extremely powerful language that has evolved from inside the browser to being used in all aspects of the tech stack with the right libraries.

At it’s heart JavaScript is a scripting language and its dynamic typing and easy to write nature means you can prototype very fast, but you have to me more careful of bugs.

Types

Like all programming languages, types play an important role in storing all different kinds of data. Unlike statically typed languages, you don’t explicitly declare the type of a variable.

Variables are declared using the let and const keywords. const should be used for all constant variables that won’t change throughout the program and let should be used for all other variables.

// Example uses of const
const API_KEY = "asdfgfdxc"
const SIZE = 50

// Variable Declarations
let str = "Hello, world" // Declaring a String
let num = 1234 // Declaring a number
let bool = true // Declaring a boolean

Arrays

Arrays are a collection of elements that can be accessed very easily. There are several ways to declare an array in JavaScript, and array access is also very fast.

// Declaring an Array
let arr1 = [1, 2, 3, 4] // An array with starting values 1, 2, 3, 4
let arr2 = [1, true, "hello, world"] // Arrays can be declared with different types
let arr3 = new Array() // An empty array
let arr4 = new Array(4) // An empty array of length 4

Built-In Functions / Properties

Within an array there are valuable built-in functions that will always remain useful:

Array.length - Returns the size of an array

Array.push(var) - Add a new array element to the end of the array

Array.pop() - Remove an item from the end of the array

Array.forEach(function(currentElement, index, array) {...}) - Loop over an array with a predefined or callback function

Array.map(function(currentElement) {...}) - Iterates over an array and returns a new array of the potentially modified elements

Array.reverse() - Reverses an array

Array.filter(function(element) {/*Returns a boolean*/}) - Returns an array of elements that pass the condition of the callback function.