Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 43d9e1d

Browse files
committed
new js questions added
2 parents f73b432 + 5d87390 commit 43d9e1d

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

‎README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,7 +1021,44 @@ This is different from the previous example where ... spread operator was used,
10211021

10221022
<details>
10231023
<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+
const companies = [
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>
10251062

10261063
```js
10271064
console.log(typeof 42);
@@ -1065,7 +1102,7 @@ The typeof operator in JavaScript is used to determine the type of a value or ex
10651102

10661103
<details>
10671104
<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>
10691106

10701107
```javascript
10711108
console.log(getType(42));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /