Skip to content

Commit e44028a

Browse files
qns: address user feedback (#29)
Co-authored-by: GitHub Actions <github-actions[bot]@users.noreply.github.com>
1 parent cefc4b0 commit e44028a

File tree

17 files changed

+87
-40
lines changed
  • questions
    • describe-event-bubbling
    • explain-event-delegation
    • explain-hoisting
    • explain-the-concept-of-a-callback-function-in-asynchronous-operations
    • how-do-you-abort-a-web-request-using-abortcontrollers
    • how-do-you-handle-errors-in-asynchronous-operations
    • how-do-you-validate-form-elements-using-the-constraint-validation-api
    • what-are-iterators-and-generators-and-what-are-they-used-for
    • what-are-some-common-performance-bottlenecks-in-javascript-applications
    • what-are-the-differences-between-xmlhttprequest-and-fetch
    • what-are-the-pros-and-cons-of-using-promises-instead-of-callbacks
    • what-is-the-definition-of-a-higher-order-function
    • what-is-the-difference-between-double-equal-and-triple-equal
    • what-is-the-difference-between-mouseenter-and-mouseover-event
    • whats-the-difference-between-a-variable-that-is-null-undefined-or-undeclared-how-would-you-go-about-checking-for-any-of-these-states
    • whats-the-difference-between-call-and-apply

17 files changed

+87
-40
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ The main difference lies in the bubbling behavior of `mouseenter` and `mouseover
10641064

10651065
`mouseenter` events do not bubble. The `mouseenter` event is triggered only when the mouse pointer enters the element itself, not its descendants. If a parent element has child elements, and the mouse pointer enters child elements, the `mouseenter` event will not be triggered on the parent element again, it's only triggered once upon entry of parent element without regard for its contents. If both parent and child have `mouseenter` listeners attached and the mouse pointer moves from the parent element to the child element, `mouseenter` will only fire for the child.
10661066

1067-
`mouseover` events bubble up the DOM tree. The `mouseover` event is triggered when the mouse pointer enters the element or one of its descendants. If have a parent element has child elements, and the mouse pointer enters child elements, the `mouseover` event will be triggered on the parent element again as well. If the parent element has multiple child elements, this can result in multiple event callbacks fired. If there are child elements, and the mouse pointer moves from the parent element to the child element, `mouseover` will fire for both the parent and the child.
1067+
`mouseover` events bubble up the DOM tree. The `mouseover` event is triggered when the mouse pointer enters the element or one of its descendants. If a parent element has child elements, and the mouse pointer enters child elements, the `mouseover` event will be triggered on the parent element again as well. If the parent element has multiple child elements, this can result in multiple event callbacks fired. If there are child elements, and the mouse pointer moves from the parent element to the child element, `mouseover` will fire for both the parent and the child.
10681068

10691069
| Property | `mouseenter` | `mouseover` |
10701070
| --- | --- | --- |
@@ -4921,7 +4921,7 @@ The main difference lies in the bubbling behavior of `mouseenter` and `mouseover
49214921

49224922
`mouseenter` events do not bubble. The `mouseenter` event is triggered only when the mouse pointer enters the element itself, not its descendants. If a parent element has child elements, and the mouse pointer enters child elements, the `mouseenter` event will not be triggered on the parent element again, it's only triggered once upon entry of parent element without regard for its contents. If both parent and child have `mouseenter` listeners attached and the mouse pointer moves from the parent element to the child element, `mouseenter` will only fire for the child.
49234923

4924-
`mouseover` events bubble up the DOM tree. The `mouseover` event is triggered when the mouse pointer enters the element or one of its descendants. If have a parent element has child elements, and the mouse pointer enters child elements, the `mouseover` event will be triggered on the parent element again as well. If the parent element has multiple child elements, this can result in multiple event callbacks fired. If there are child elements, and the mouse pointer moves from the parent element to the child element, `mouseover` will fire for both the parent and the child.
4924+
`mouseover` events bubble up the DOM tree. The `mouseover` event is triggered when the mouse pointer enters the element or one of its descendants. If a parent element has child elements, and the mouse pointer enters child elements, the `mouseover` event will be triggered on the parent element again as well. If the parent element has multiple child elements, this can result in multiple event callbacks fired. If there are child elements, and the mouse pointer moves from the parent element to the child element, `mouseover` will fire for both the parent and the child.
49254925

49264926
| Property | `mouseenter` | `mouseover` |
49274927
| --- | --- | --- |

questions/describe-event-bubbling/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ child.click();
8585

8686
## Event delegation
8787

88-
Event bubbling is the basis for a technique called [event delegation](/questions/quiz/describe-event-delegation), where you attach a single event handler to a common ancestor of multiple elements and use event delegation to handle events for those elements efficiently. This is particularly useful when you have a large number of similar elements, like a list of items, and you want to avoid attaching individual event handlers to each item.
88+
Event bubbling is the basis for a technique called [event delegation](/questions/quiz/explain-event-delegation), where you attach a single event handler to a common ancestor of multiple elements and use event delegation to handle events for those elements efficiently. This is particularly useful when you have a large number of similar elements, like a list of items, and you want to avoid attaching individual event handlers to each item.
8989

9090
```js
9191
parent.addEventListener('click', (event) => {

questions/explain-event-delegation/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ userForm.addEventListener('input', (event) => {
108108
});
109109
```
110110

111-
In this example, a single input event listener is attached to the form element. It can respond to input changes for all child input elements, simplifying the code by an event listeners per `<input>` element.
111+
In this example, a single input event listener is attached to the form element. It can respond to input changes for all child input elements, simplifying the code by eliminating the need for individual listeners on each `<input>` element.
112112

113113
## Pitfalls
114114

questions/explain-hoisting/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,4 @@ ESLint is a static code analyzer that can find violations of such cases with the
140140
## Further reading
141141

142142
- [Hoisting | MDN](https://developer.mozilla.org/en-US/docs/Glossary/Hoisting)
143-
- [JavaScript Visualized: Hoisting](https://dev.to/lydiahallie/javascript-visualized-hoisting-478h)
143+
- [What is Hoisting in JavaScript?](https://www.freecodecamp.org/news/what-is-hoisting-in-javascript)

questions/explain-the-concept-of-a-callback-function-in-asynchronous-operations/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,4 @@ fetchData((error, data) => {
9696

9797
- [MDN Web Docs: Callback function](https://developer.mozilla.org/en-US/docs/Glossary/Callback_function)
9898
- [JavaScript.info: Callbacks](https://javascript.info/callbacks)
99-
- [Node.js: Asynchronous programming and callbacks](https://nodejs.org/en/knowledge/getting-started/control-flow/what-are-callbacks/)
99+
- [Node.js: Asynchronous programming and callbacks](https://nodejs.org/en/learn/asynchronous-work/javascript-asynchronous-programming-and-callbacks)

questions/how-do-you-abort-a-web-request-using-abortcontrollers/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ In situations where the user has navigated away from the page, aborting the requ
153153
## Notes
154154

155155
- `AbortController`s is not `fetch()`-specific, it can be used to abort other asynchronous tasks as well.
156-
- A singular `AbortContoller` instance can be reused or multiple async tasks and cancel all of them at once.
156+
- A singular `AbortContoller` instance can be reused on multiple async tasks and cancel all of them at once.
157157
- Calling `abort()` on `AbortController`s does not send any notification or signal to the server. The server is unaware of the cancelation and will continue processing the request until it completes or times out.
158158

159159
## Further reading

questions/how-do-you-handle-errors-in-asynchronous-operations/en-US.mdx

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,28 +58,33 @@ fetchData(); // Error fetching data: ....
5858
If you have multiple asynchronous operations, you can nest `try...catch` blocks to handle errors at different levels.
5959

6060
```js live
61-
async function fetchData() {
62-
try {
63-
// Invalid URl
64-
const response = await fetch('https://api.example.com/data');
65-
const data = await response.json();
66-
console.log(data);
67-
} catch (error) {
68-
console.error('Error fetching data:', error);
69-
}
61+
async function fetchUser() {
62+
// Simulate a successful async operation
63+
return { id: 1, name: 'Alice' };
7064
}
7165

72-
async function processData() {
66+
async function fetchUserPosts() {
67+
// Simulate a failed async operation
68+
throw new Error('Failed to fetch posts');
69+
}
70+
71+
async function loadUserData() {
7372
try {
74-
await fetchData();
75-
// Additional processing
76-
console.log(arr); // Trying to reference an undefined variable will throw an error
77-
} catch (error) {
78-
console.error('Error processing data:', error);
73+
const user = await fetchUser();
74+
console.log('User:', user);
75+
76+
try {
77+
const posts = await fetchUserPosts();
78+
console.log('Posts:', posts);
79+
} catch (postsError) {
80+
console.error('Error fetching posts:', postsError.message);
81+
}
82+
} catch (userError) {
83+
console.error('Error fetching user:', userError.message);
7984
}
8085
}
8186

82-
processData();
87+
loadUserData();
8388
```
8489

8590
## Using `.catch()` with Promises

questions/how-do-you-validate-form-elements-using-the-constraint-validation-api/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,4 +115,4 @@ In this example, the form will not submit if the `username` input is empty, and
115115

116116
- [MDN Web Docs: Constraint Validation](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Constraint_validation)
117117
- [MDN Web Docs: HTMLFormElement.checkValidity()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/checkValidity)
118-
- [MDN Web Docs: HTMLFormElement.setCustomValidity()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/setCustomValidity)
118+
- [MDN Web Docs: HTMLObjectElement.setCustomValidity()](https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/setCustomValidity)

questions/what-are-iterators-and-generators-and-what-are-they-used-for/en-US.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ In JavaScript, several built-in objects implement the iterator protocol, meaning
179179

180180
Generators are a special kind of function that can pause and resume their execution, allowing them to generate a sequence of values on-the-fly. They are commonly used to create iterators but have other applications as well. The key use cases of generators include:
181181

182-
- Creating iterators is a more concise and readable way compared to manually implementing the iterator protocol.
182+
- Creating iterators in a more concise and readable way compared to manually implementing the iterator protocol.
183183
- Implementing lazy evaluation, where values are generated only when needed, saving memory and computation time.
184184
- Simplifying asynchronous programming by allowing code to be written in a synchronous-looking style using `yield` and `await`.
185185

questions/what-are-some-common-performance-bottlenecks-in-javascript-applications/en-US.mdx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,22 @@ Layout thrashing occurs when you read and write to the DOM repeatedly, causing m
3838

3939
```js
4040
// Inefficient
41-
for (let i = 0; i < 1000; i++) {
42-
const height = element.clientHeight;
43-
element.style.height = `${height + 10}px`;
44-
}
41+
boxes.forEach((box) => {
42+
const height = box.offsetHeight; // Read
43+
box.style.height = `${height + 10}px`; // Write
44+
});
4545

4646
// Efficient
47-
const height = element.clientHeight;
48-
for (let i = 0; i < 1000; i++) {
49-
element.style.height = `${height + 10}px`;
50-
}
47+
// Batch read
48+
const heights = [];
49+
boxes.forEach((box) => {
50+
heights.push(box.offsetHeight);
51+
});
52+
53+
// Batch write
54+
boxes.forEach((box, i) => {
55+
box.style.height = `${heights[i] + 10}px`;
56+
});
5157
```
5258

5359
## Excessive use of global variables

0 commit comments

Comments
 (0)