You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+39-2Lines changed: 39 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1021,7 +1021,44 @@ This is different from the previous example where ... spread operator was used,
1021
1021
1022
1022
<details>
1023
1023
<summary>
1024
-
<h3>34. Guess the output of the following code that uses the typeof operator.</h3>
1024
+
<h3>34. What is the output of the following code?</h3>
1025
+
1026
+
```jsx
1027
+
constcompanies= [
1028
+
{ id:"1", name:"Facebook" },
1029
+
{ id:"2", name:"Apple" },
1030
+
{ id:"3", name:"Google" },
1031
+
];
1032
+
1033
+
companies.sort((a, b) => (a.name>b.name?-1:1));
1034
+
console.log(companies);
1035
+
```
1036
+
1037
+
</summary>
1038
+
1039
+
The output of the code will be:
1040
+
1041
+
Answer:
1042
+
1043
+
```bash
1044
+
[
1045
+
{id: "3", name:"Google"},
1046
+
{id: "1", name:"Facebook"},
1047
+
{id: "2", name:"Apple"}
1048
+
]
1049
+
```
1050
+
1051
+
The comparison function takes two parameters, "a" and "b", which represent two elements being compared in the array.
1052
+
1053
+
If the "name" property of "a" comes before the "name" property of "b" in alphabetical order, then the function returns -1, which means "a" should come before "b" in the sorted array.
1054
+
1055
+
Otherwise, if the "name" property of "a" comes after the "name" property of "b" in alphabetical order, then the function returns 1, which means "b" should come before "a" in the sorted array.
1056
+
1057
+
</details>
1058
+
1059
+
<details>
1060
+
<summary>
1061
+
<h3>35. Guess the output of the following code that uses the typeof operator.</h3>
1025
1062
1026
1063
```js
1027
1064
console.log(typeof42);
@@ -1065,7 +1102,7 @@ The typeof operator in JavaScript is used to determine the type of a value or ex
1065
1102
1066
1103
<details>
1067
1104
<summary>
1068
-
<h3>35. Write a function in JavaScript to determine the type of a value.</h3>
1105
+
<h3>36. Write a function in JavaScript to determine the type of a value.</h3>
0 commit comments