-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore_predictJavaScript.js
More file actions
82 lines (71 loc) · 2.89 KB
/
Core_predictJavaScript.js
File metadata and controls
82 lines (71 loc) · 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// 1. Output:
// Tesla
// Mercedes
// Reason: because randomCar refers to an index of 0 in the array of cars, and otherRandomCar refers to index 1.
// Index value:
// const [ , , thirdCar] = cars
// console.log(thirdCar)
// 2. Output:
// Elon
// Error
// In order to fix it.
const { employeeName, employeeName: otherName } = employee;
console.log(employeeName);
console.log(otherName);
// 3. Output:
// 12345
// undefined
// In order to fix it:
const person = {
name: 'Phil Smith',
age: 47,
height: '6 feet',
password : '12345'
}
const { password, password: hashedPassword } = person;
console.log(password);
console.log(hashedPassword);
// 4. Output:
// false
// true
// Reason: because first refers to index of 1, second refers to index of 3, and third refers to index of 8. Numbers[1] != Numbers[3], Numbers[1] == Numbers[8]
const [ , , , , fourth, , , , ,] = numbers;
console.log(fourth);
// 5. Output:
// value
// [1,5,1,8,3,3]
// 1
// 5
console.log(secondKey[5]);
// 6. Scopes:
// Global Scope:
// Variables and functions declared at the top level.
// Contains the variable beatles and the function printNames
// Function Scope:
// Contains variables and functions defined inside printNames
// Includes the names parameter and the actuallyPrintingNames function.
// Inner Function Scope:
// Includes index and name
// Contains variables defined within the actuallyPrintingNames function.
//Output:
// Paul was found at index 0
// George was found at index 1
// John was found at index 2
// Ringo was found at index 3
// name and index after loop is Ringo:4
// 7. Output:
// Nothing, because the function was not being called.
// 8. Output:
// Paul was found at index 0
// George was found at index 1
// John was found at index 2
// Ringo was found at index 3
// The array reference does not need to change, so const beatles ensures immutability of the variable reference.
// The index variable changes with each loop iteration, requiring mutability, which is let
// The name variable does not need to change within an iteration.
// 9. Output:
// true
// flase
// planet.composition[0] refers to the first element of the composition array in the planet, which is the string "gas".
// planetCopy.composition[0] also refers to the same element because composition is not deep copied—it’s the same array reference for both objects.
// JavaScript compares objects by reference, not by value. Since planet and planetCopy point to different memory locations, this comparison returns false.