Lab 3Variables and ConstantsfunctionScoped = 2blockScoped = 5 constant1 = -3 name = Zhenming Gao greeting = Helloo Zhenming Gao! sampleSum = 7 Variables TypesnumberVariable = 123floatingPointNumber = 234.345 stringVariable = Hello World! booleanVariable = true isNumber = number isString = string isBoolean = boolean string2, bool2 = string2, false isString2, isBool2 = string, boolean sampleCount = 42 sampleLabel = Lab 3 sampleCountT = number sampleLabelT = string Boolean Variablestrue1 = truefalse1 = false false2 = false true2 = true true3 = true true4 = true true5 = true false3 = false true6 = true "123" === 123 = false "123" == 123 = true If Elsetrue1 !false1 not false1 Logged InWelcome Free Good morning Welcome If ElsePlease login InlineAdmin InlineGuest InlineNull vs UndefinednullValue = nullundefinedValue = undefined typeof nullValue = object typeof undefinedValue = undefined String(null) = null String(undefined) = undefined nullValue ?? "default" = default null == undefined = true null === undefined = false FunctionsLegacy ES5 functionstwoPlusFour = 6add(2, 4) = 6 subtract(2, 4) = -2 multiply(3, 7) = 21 threeTimesSeven = 21 New ES6 arrow functionsthreeMinusOne = 2subtract(3, 1) = 2 multiply(3, 4) = 7 add(2, 4) = 6 Implied returnfourTimesFive = 20multiply(4, 5) = 20 square(9) = 81 divide(4, 5) = 0.8 Template Literalsresult1 = 2 + 3 = 5result2 = 2 + 3 = 5 greeting1 = Welcome home alice greeting2 = Logged in: No courseStatus = RS101 published: Yes konst(true)(false) ? name : "" = Zhenming Gao Simple ArraysnumberArray1 = 12345stringArray1 = string1string2 variableArray1 = 25-312345string1string2 Todo list:
Array index and lengthlength1 = 5index1 = 2 indexOf1 = 0 numberArray1.indexOf(9) = -1 Add/remove to/from arraysnumberArray1 = 12456stringArray1 = string1string3 Todo list:
Looping through arraysstringArray2 = STRING1STRING3stringLengths = 77 stringArray3 = string1string3 Map Functionsquares = 149162536cubes = 182764125216 doubles = 24681012 Todos:
Find Functionfour = 4string3 = string3 findNonexistent = undefined two = 2 Find Index FunctionfourIndex = 2string3Index = 1 threeIndex = -1 sixIndex = 4 Filter FunctionnumbersGreaterThan2 = 456evenNumbers = 246 oddNumbers = 15 numbersLessThan2 = 1 numbersGreaterThan5 = 56 Includes, Some, Everyincludes(3) = trueincludes(8) = false some(n > 4) = true every(n > 0) = true includes(5) = true every(n > 4) = false some(n === 1) = true Reduce Functionsum = 15product = 120 joined = 12345 JSON Stringifysquares = [1,4,16,25,36]rs101 = {"course":"RS102","modules":3} sampleCourse = {"course":"RS102","modules":3} Housebedrooms4bathrooms2.5year built2004cars in garage2ownersAlice, BobData{
"bedrooms": 4,
"bathrooms": 2.5,
"squareFeet": 2000,
"yearBuilt": 2004,
"address": {
"street": "Via Roma",
"city": "Roma",
"state": "RM",
"zip": "00100",
"country": "Italy"
},
"owners": [
"Alice",
"Bob"
],
"garage": {
"cars": 2
}
}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} {"a":999,"b":2,"c":3,"d":4,"e":5,"f":6} [1,2,3,4,5,6,7] DestructingObject Destructingconst { name, age } = { name: "John", age: 25 }name = John age = 25 city = Boston Array Destructingconst [first, second, third, fourth] = ["one","two","three","four"]first = one second = two third = three fourth = four 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 }); const product = multiply({ a: 4, b: 2 }); const greeting = greet(); sum = 3 difference = 2 product = 8 greeting = Hello, ada Destructing Imports
Optional Chaininghouse.address?.city = Romamissing?.prop ?? "n/a" = n/a house.garage?.cars ?? 0 = 0 house.address?.zip ?? "unknown" = unknown ClassesYellow background Blue background Red background Dynamic Blue background Dangerous background Dynamic GREEN background. Dynamic Green background (AI) StylesYellow background Red background Blue background Green background Gray background Client Component DemoCurrent pathname: /labs/lab3 Last segment: lab3 Pathname length: 10 Server Component DemoServer Render TimeRendered on server at: 8:34:15 AM Server Information{
"platform": "linux",
"nodeVersion": "v24.22.3",
"serverRenderTime": "8:34:15 AM",
"arch": "x64",
"pid": 86
}Filesystem Access Demo[ "Add.tsx", "AddingAndRemovingToFromArrays.tsx", "ArrayIndexAndLength.tsx", "ArrowFunctions.tsx", "BooleanVariables.tsx", "Classes.css", "Classes.tsx", "ClientComponentDemo.tsx", "ConditionalOutputIfElse.tsx", "ConditionalOutputInline.tsx", "DestructingImports.tsx", "Destructuring.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", "page.tsx", "todos" ] Adda = 3b = 4a + b = 7 Adda = 10b = 20a + b = 30 Adda = 7b = 8a + b = 15 Square of 416Square of 981Square of 5 = 25 Lorem ipsum dolor, sit amet consectetur adipisicing elit. Omnis natus dolores incidunt quasi ipsa, itaque quae iste eum. Inventore, velit earum consequatur distinctio sunt ad vel asperiores aliquid quisquam eius. Children can be any JSX Todo List
|