Lab 3

Variables and Constants

functionScoped = 2
blockScoped = 5
constant1 = -3

Variables Types

numberVariable = 123
floatingPointNumber = 234.345
stringVariable = Hello World!
booleanVariable = true
isNumber = number
isString = string
isBoolean = boolean

Boolean Variables

true1 = true
false1 = false
false2 = false
true2 = true
true3 = true
true4 = true
true5 = true
false3 = false

If Else

true1

!false1


Logged In

Welcome


Welcome If Else

Please login Inline

Functions

Legacy ES5 functions
twoPlusFour = 6
add(2, 4) = 6

New ES6 arrow functions

threeMinusOne = 2
subtract(3, 1) = 2

Implied return

fourTimeFive = 20
multiply(4, 5) = 20

Template Literals

result1 = 2 + 3 = 5
result2 = 2 + 3 = 5
greeting1 = Welcome home alice
greeting2 = Logged in: No

Simple Arrays

numberArray1 = 12345
stringArray1 = string1string2
variableArray1 = 25-312345string1string2
Todo list:
  1. Buy milk
  2. Feed the pets

Array index and length

length1 = 5
index1 = 2

Add/remove to/from arrays

numberArray1 = 12456
stringArray1 = string1string3
Todo list:
  1. Buy milk
  2. Feed the pets
  3. Walk the dogs

Looping through arrays

stringArray2 = STRING1STRING3

Map Function

squares = 149162536
cubes = 182764125216
Todos:
  1. Buy milk
  2. Feed the pets

Find Function

four = 4
string3 = string3

FindIndex Function

fourIndex = 2
string3index = 1

Filter Function

numbersGreaterThan2 = 456
evenNumbers = 246
oddNumbers = 15

JSON Stringify

squares = [1,4,16,25,36]

House

bedrooms
4
bathrooms
2.5
Data
{
  "bedrooms": 4,
  "bathrooms": 2.5,
  "squareFeet": 2000,
  "address": {
    "street": "Via Roma",
    "city": "Roma",
    "state": "RM",
    "zip": "00100",
    "country": "Italy"
  },
  "owners": [
    "Alice",
    "Bob"
  ]
}

Spread Operator

Array Spread

arr1 = [1,2,3]
arr2 = [1,2,3,4,5,6]

Object Spread

{"a":1,"b":2,"c":3}
{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6}
{"a":1,"b":4,"c":3}

Destructing

Object Destructing

const { name, age } = { name: "John", age: 25 }

name = John
age = 25

Array Destructing

const [first, second, third] = ["one", "two", "three"]

first = one
second = two
third = three

Function Destructing

const add = (a, b) => a + b;
const sum = add(1, 2);
const subtract = ({ a, b }) => a - b;
const difference = subtract({ a: 4, b: 2 });
sum = 3
difference = 2

Destructing Imports

MathMatematicaFunctions
Math.add(2, 3) = 5Matematica.add(2, 3) = 5add(2, 3) = 5
Math.subtract(5, 1) = 4Matematica.subtract(5, 1) = 4subtract(5, 1) = 4
Math.multiply(3,4) = 12Matematica.multiply(3,4) = 12multiply(3, 4) = 12
Math.divide(8 ,2) = 4Matematica.divide(8, 2) = 4divide(8, 2) = 4

Classes

Dangerous background
Dynamic Blue background
Yellow background
Blue background
Red background

Styles

Yellow background
Red background
Blue background

Add

a = 3b = 4
a + b = 7

Sqaure of 4

16
Lorem ipsum dolor sit amet consectetur adipisicing elit. Suscipitratione eaque illo minus cum, saepe totam vel nihil repellat nemo explicabo excepturi consectetur. Modi omnis minus sequi maiores, provident voluptates.

Path Parameters

1 + 2
3 + 4
Buy milk (Completed)

Todo List

Buy milk (CANCELED)
Pickup the kids (IN PROGRESS)
Walk the dog (DEFERRED)