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 5d87390

Browse files
Update README.md
Refactored question 34.
1 parent 7ab075a commit 5d87390

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

‎README.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: "Prepare for your next 2023 JavaScript interview with these tricky
44
githubPath: "https://github.com/Vasu7389/JavaScript-Interview-Questions-2023"
55
---
66

7-
<span style=" font-size: 1rem; border-bottom: 1px solid grey;"> Updated Apr 16, 2023 </span>
7+
<span style=" font-size: 1rem; border-bottom: 1px solid grey;"> Updated Apr 30, 2023 </span>
88

99
In this article, we will cover a range of JavaScript interview questions, including those related to the latest versions of the language (ES6, ES7, ES8, and ES9).
1010

@@ -1024,14 +1024,14 @@ This is different from the previous example where ... spread operator was used,
10241024
<h3>34. What is the output of the following code?</h3>
10251025

10261026
```jsx
1027-
var companies = [
1027+
const companies = [
10281028
{id: "1", name:"Facebook"},
10291029
{id: "2", name:"Apple"},
10301030
{id: "3", name:"Google"},
1031-
]
1031+
];
10321032

1033-
companies.sort((a,b) => (a.name > b.name ? -1 : 1))
1034-
console.log(companies)
1033+
companies.sort((a,b) => (a.name > b.name ? -1 : 1));
1034+
console.log(companies);
10351035

10361036
```
10371037

@@ -1042,9 +1042,15 @@ The output of the code will be:
10421042
Answer:
10431043

10441044
```bash
1045-
[ {id: "3", name:"Google"} , {id: "1", name:"Facebook"} , {id: "2", name:"Apple"} ]
1045+
[
1046+
{id: "3", name:"Google"},
1047+
{id: "1", name:"Facebook"},
1048+
{id: "2", name:"Apple"}
1049+
]
10461050
```
10471051

1048-
The comparison function takes two parameters, "a" and "b", which represent two elements being compared in the array. 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. 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.
1052+
The comparison function takes two parameters, "a" and "b", which represent two elements being compared in the array.
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+
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.
10491055

10501056
</details>

0 commit comments

Comments
(0)

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