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 InlineNull vs UndefinednullValue = nullundefinedValue = undefined typeof nullValue = object typeof undefinedValue = undefined String(null) = null String(undefined) = undefined FunctionsLegacy 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 = 2string3Index = 1 Filter FunctionnumbersGreaterThan2 = 456evenNumbers = 246 oddNumbers = 15 Includes, Some, Everyincludes(3) = trueincludes(8) = false some(n > 4) = true every(n > 0) = true Reduce Functionsum = 15JSON 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
Optional Chaininghouse.address?.city = Romamissing?.prop ?? "n/a" = n/a ClassesYellow background Blue background Red background Dynamic Blue background Dangerous background StylesYellow background Red background Blue background Client Component DemoCurrent pathname: /labs/lab3 Server Component DemoServer Render TimeRendered on server at: 9:25:21 PM Server Information{
"platform": "linux",
"nodeVersion": "v24.19.0",
"serverRenderTime": "9:25:21 PM"
}Filesystem Access Demo[ "Add.tsx", "AddingAndRemovingToFromArrays.tsx", "ArrayIndexAndLength.tsx", "ArrowFunctions.tsx", "BooleanVariables.tsx", "Classes.css", "Classes.tsx", "ClientComponentDemo.tsx", "ConditionalOutputIfElse.tsx", "ConditionalOutputInline.tsx", "Destructing.tsx", "DestructingImports.tsx", "FilterFunction.tsx", "FindFunction.tsx", "FindIndex.tsx", "ForLoops.tsx", "FunctionDestructing.tsx", "Highlight.tsx", "House.tsx", "IfElse.tsx", "ImpliedReturn.tsx", "IncludesSomeEvery.tsx", "JsonStringify.tsx", "LegacyFunctions.tsx", "MapFunction.tsx", "Math.ts", "NullUndefined.tsx", "OptionalChaining.tsx", "PathParameters.tsx", "ReduceFunction.tsx", "ServerComponentDemo.tsx", "SimpleArrays.tsx", "Spreader.tsx", "Square.tsx", "Styles.tsx", "TemplateLiterals.tsx", "TernaryOperator.tsx", "VariableTypes.tsx", "VariablesAndConstants.tsx", "add", "intermediates", "page.tsx", "todos" ] Adda = 3b = 4a + b = 7 Square of 416Lorem ipsum dolor sit amet, consectetur adipisicing elit. Todo List
|