Skip to content

Latest commit

 

History

History
144 lines (103 loc) · 1.77 KB

README.md

File metadata and controls

144 lines (103 loc) · 1.77 KB

Installing VSCode

Get VisualStudio Code from here.

Installing NodeJS

Ubuntu

Run these three lines in your terminal.

sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install nodejs

Windows and Mac

Get NodeJS from here.

Developer Tools

Browser Console Inspector
🔥🦊 Ctrl + Shift + K Ctrl + Shift + C
Chrome Ctrl + Shift + J Ctrl + Shift + C

JavaScript Basics

Variables

If are not going to initialize again (use this most of the time)

const four = 4

If you are going to initialize again

let four = 4

Control

if (four == 4) {
  console.log("is four")
} else {
  console.log("is not four")
}

Loops

Regular for loops

for (let i = 0; i < 4; i++) {
  console.log(i)
}

While loop

let i = 0
while (i < 4) {
  console.log(i)
  i++
}

Functions

Regular functions

function addFour(n) {
  return n + 4
}

New stateless functions

const addFour = (n) => {
  return n + 4
}

or

const addFour = n => n + 4

Arrays

const arr = ["zero", "one", "two", "three", "four"]

then iterate through them

arr.forEach(str => {
  console.log(str)
})

or add four to each element

const newArr = arr.map(str => str + 4)

Objects

const obj = {
  name: "Caleb",
  favoriteNumbers: [
    2,
    4,
    42
  ],
  anotherObj: {
    nestedProp: "🇨🇦"
  }
}

Access the properties with:

const canadaEmoji = obj.anotherObj.nestedProp

or:

const canadaEmoji = obj["anotherObj"]["nestedProp"]