Lab 3Variables and ConstantsfunctionScoped = 2blockScoped = 5 constant1 = -3 Variables TypesnumberVariable = 123floatingPointNumber = 234.345 stringVariable = Hello World! booleanVariable = true isNumber = number isString = string isBoolean = boolean Boolean Variablestrue1 = truefalse1 = false false2 = false true2 = true true3 = true true4 = true true5 = true false3 = false If Elsetrue1 !false1 Logged InWelcome Welcome If ElsePlease login InlineFunctionsLegacy ES5 functionstwoPlusFour = 6add(2, 4) = 6 New ES6 arrow functionsthreeMinusOne = 2subtract(3, 1) = 2 Implied returnfourTimesFive = 20multiply(4, 5) = 20 Template Literalsresult1 = 2 + 3 = 5result2 = 2 + 3 = 5 greeting1 = Welcome home alice greeting2 = Logged in: No Simple ArraysnumberArray1 = 12345stringArray1 = string1string2 variableArray1 = 25-312345string1string2 Todo list:
Array index and lengthlength1 = 5index1 = 2 Add/remove to/from arraysnumberArray1 = 12456stringArray1 = string1string3 Todo list:
Looping through arraysstringArray2 = STRING1STRING3Map Functionsquares = 149162536cubes = 182764125216 Todos:
Find Functionfour = 4string3 = string3 Find Index FunctionfourIndex = 2 String3Index = 1 Filter FunctionnumbersGreaterThan2 = 456evenNumbers = 246 oddNumbers = 15 JSON Stringifysquares = [1,4,16,25,36]Housebedrooms4bathrooms2.5Data{
"bedrooms": 4,
"bathrooms": 2.5,
"squareFeet": 2000,
"address": {
"street": "Via Roma",
"city": "Roma",
"state": "RM",
"zip": "00100",
"country": "Italy"
},
"owners": [
"Alice",
"Bob"
]
}Spread OperatorArray Spreadarr1 = [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} DestructingObject Destructingconst { name, age } = { name: “John“, age: 25 }name = John age = 25 Array Destructingconst [first, second, third] = [“one“,“two“,“three“]first = one second = two third = three Function Destructingconst 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
ClassesDangerous background Dynamic Blue background Yellow background Blue background Red background StylesYellow background Red background Blue background Adda = 3b = 5 a + b = 8 Square of 525Lorem 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. Buy milk (COMPLETED) Todo ListBuy milk (CANCELED) Pickup the kids (IN PROGRESS) Walk the dog (DEFERRED) |