Skip to content

Commit b9cc573

Browse files
committed
qns: fix reported JavaScript content defects
Resolve vetted production feedback across the JavaScript question set by replacing unsafe or stale resources, correcting runtime and storage explanations, and fixing localized terminology and examples. Regenerate the README so its embedded answers remain consistent with the question sources.
1 parent bd3cbe8 commit b9cc573

27 files changed

Lines changed: 93 additions & 99 deletions

File tree

‎README.md‎

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ The event loop is a concept within the JavaScript runtime environment regarding
387387
3. Once the asynchronous operation completes, its callback function is placed in the respective queues – task queues (also known as macrotask queues / callback queues) or microtask queues. We will refer to "task queue" as "macrotask queue" from here on to better differentiate from the microtask queue.
388388
4. The event loop continuously monitors the call stack and executes items on the call stack. If/when the call stack is empty:
389389
1. Microtask queue is processed. Microtasks include promise callbacks (`then`, `catch`, `finally`), `await` continuations, `MutationObserver` callbacks, and calls to `queueMicrotask()`. The event loop takes the first callback from the microtask queue and pushes it to the call stack for execution. This repeats until the microtask queue is empty.
390-
2. Macrotask queue is processed. Macrotasks include web APIs like `setTimeout()`, HTTP requests, user interface event handlers like clicks, scrolls, etc. The event loop dequeues the first callback from the macrotask queue and pushes it onto the call stack for execution. However, after a macrotask queue callback is processed, the event loop does not proceed with the next macrotask yet! The event loop first checks the microtask queue. Checking the microtask queue is necessary as microtasks have higher priority than macrotask queue callbacks. The macrotask queue callback that was just executed could have added more microtasks!
390+
2. Macrotask queue is processed. It contains tasks scheduled by the host, such as timer callbacks and user interface event callbacks. APIs such as `setTimeout()` and networking APIs are not themselves macrotasks; they arrange for callbacks or promise reactions to be queued when appropriate. The event loop dequeues the first callback from the macrotask queue and pushes it onto the call stack for execution. However, after a macrotask queue callback is processed, the event loop does not proceed with the next macrotask yet! The event loop first checks the microtask queue. Checking the microtask queue is necessary as microtasks have higher priority than macrotask queue callbacks. The macrotask queue callback that was just executed could have added more microtasks!
391391
1. If the microtask queue is non-empty, process them as per the previous step.
392392
2. If the microtask queue is empty, the next macrotask queue callback is processed. This repeats until the macrotask queue is empty.
393393
5. This process continues indefinitely, allowing the JavaScript engine to handle both synchronous and asynchronous operations efficiently without blocking the call stack.
@@ -475,7 +475,7 @@ Here's a table summarizing the 3 client storage mechanisms.
475475
| Lifespan | As specified | Until deleted | Until tab is closed |
476476
| Persistent across browser sessions | If a future expiry date is set | Yes | No |
477477
| Sent to server with every HTTP request | Yes, sent via `Cookie` header | No | No |
478-
| Total capacity (per domain) | 4KB | 5MB | 5MB |
478+
| Typical storage limit | About 4 KB per cookie | About 5 MB per origin (browser-dependent) | About 5 MB per origin (browser-dependent) |
479479
| Access | Across windows/tabs | Across windows/tabs | Same tab |
480480
| Security | JavaScript cannot access `HttpOnly` cookies | None | None |
481481

@@ -1331,7 +1331,7 @@ Common use cases include:
13311331
- **New JavaScript Methods**: For example, `Array.prototype.includes()`, `Object.assign()`, etc.
13321332
- **New APIs**: Such as `fetch()`, `Promise`, `IntersectionObserver`, etc. Modern browsers support these now, but for a long time they had to be polyfilled.
13331333

1334-
Libraries and services for polyfills:
1334+
A commonly used polyfill library is:
13351335

13361336
- **`core-js`**: A modular standard library for JavaScript which includes polyfills for a wide range of ECMAScript features.
13371337

@@ -1341,11 +1341,7 @@ Libraries and services for polyfills:
13411341
[1, 2].flatMap((it) => [it, it]); // => [1, 1, 2, 2]
13421342
```
13431343

1344-
- **Polyfill.io**: A service that provides polyfills based on the features and user agents specified in the request.
1345-
1346-
```js
1347-
<script src="https://polyfill.io/v3/polyfill.min.js"></script>
1348-
```
1344+
Prefer installing maintained polyfills as project dependencies and bundling them with your application instead of loading executable code from a third-party polyfill service at runtime.
13491345

13501346
<!-- Update here: /questions/what-are-javascript-polyfills-for/en-US.mdx -->
13511347

@@ -3753,7 +3749,7 @@ The event loop is a concept within the JavaScript runtime environment regarding
37533749
3. Once the asynchronous operation completes, its callback function is placed in the respective queues – task queues (also known as macrotask queues / callback queues) or microtask queues. We will refer to "task queue" as "macrotask queue" from here on to better differentiate from the microtask queue.
37543750
4. The event loop continuously monitors the call stack and executes items on the call stack. If/when the call stack is empty:
37553751
1. Microtask queue is processed. Microtasks include promise callbacks (`then`, `catch`, `finally`), `await` continuations, `MutationObserver` callbacks, and calls to `queueMicrotask()`. The event loop takes the first callback from the microtask queue and pushes it to the call stack for execution. This repeats until the microtask queue is empty.
3756-
2. Macrotask queue is processed. Macrotasks include web APIs like `setTimeout()`, HTTP requests, user interface event handlers like clicks, scrolls, etc. The event loop dequeues the first callback from the macrotask queue and pushes it onto the call stack for execution. However, after a macrotask queue callback is processed, the event loop does not proceed with the next macrotask yet! The event loop first checks the microtask queue. Checking the microtask queue is necessary as microtasks have higher priority than macrotask queue callbacks. The macrotask queue callback that was just executed could have added more microtasks!
3752+
2. Macrotask queue is processed. It contains tasks scheduled by the host, such as timer callbacks and user interface event callbacks. APIs such as `setTimeout()` and networking APIs are not themselves macrotasks; they arrange for callbacks or promise reactions to be queued when appropriate. The event loop dequeues the first callback from the macrotask queue and pushes it onto the call stack for execution. However, after a macrotask queue callback is processed, the event loop does not proceed with the next macrotask yet! The event loop first checks the microtask queue. Checking the microtask queue is necessary as microtasks have higher priority than macrotask queue callbacks. The macrotask queue callback that was just executed could have added more microtasks!
37573753
1. If the microtask queue is non-empty, process them as per the previous step.
37583754
2. If the microtask queue is empty, the next macrotask queue callback is processed. This repeats until the macrotask queue is empty.
37593755
5. This process continues indefinitely, allowing the JavaScript engine to handle both synchronous and asynchronous operations efficiently without blocking the call stack.
@@ -5032,7 +5028,7 @@ Here's a table summarizing the 3 client storage mechanisms.
50325028
| Lifespan | As specified | Until deleted | Until tab is closed |
50335029
| Persistent across browser sessions | If a future expiry date is set | Yes | No |
50345030
| Sent to server with every HTTP request | Yes, sent via `Cookie` header | No | No |
5035-
| Total capacity (per domain) | 4KB | 5MB | 5MB |
5031+
| Typical storage limit | About 4 KB per cookie | About 5 MB per origin (browser-dependent) | About 5 MB per origin (browser-dependent) |
50365032
| Access | Across windows/tabs | Across windows/tabs | Same tab |
50375033
| Security | JavaScript cannot access `HttpOnly` cookies | None | None |
50385034

@@ -5326,7 +5322,7 @@ Common use cases include:
53265322
- **New JavaScript Methods**: For example, `Array.prototype.includes()`, `Object.assign()`, etc.
53275323
- **New APIs**: Such as `fetch()`, `Promise`, `IntersectionObserver`, etc. Modern browsers support these now, but for a long time they had to be polyfilled.
53285324

5329-
Libraries and services for polyfills:
5325+
A commonly used polyfill library is:
53305326

53315327
- **`core-js`**: A modular standard library for JavaScript which includes polyfills for a wide range of ECMAScript features.
53325328

@@ -5336,11 +5332,7 @@ Libraries and services for polyfills:
53365332
[1, 2].flatMap((it) => [it, it]); // => [1, 1, 2, 2]
53375333
```
53385334

5339-
- **Polyfill.io**: A service that provides polyfills based on the features and user agents specified in the request.
5340-
5341-
```js
5342-
<script src="https://polyfill.io/v3/polyfill.min.js"></script>
5343-
```
5335+
Prefer installing maintained polyfills as project dependencies and bundling them with your application instead of loading executable code from a third-party polyfill service at runtime.
53445336

53455337
<!-- Update here: /questions/what-are-javascript-polyfills-for/en-US.mdx -->
53465338

‎questions/can-you-offer-a-use-case-for-the-new-arrow-function-syntax-how-does-this-new-syntax-differ-from-other-functions/en-US.mdx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ function Timer() {
4848
}
4949

5050
const timer = new Timer();
51-
timer.increment(); // 1
52-
timer.increment(); // 2
51+
const increment = timer.increment;
52+
increment(); // 1
53+
increment(); // 2
5354
```
5455

55-
In the example above, using a traditional function for `increment` would lose the correct `this` context when called, requiring additional steps like `bind` to fix it.
56+
In the example above, `increment` is called without `timer` as its receiver, but the arrow function still uses the `this` value captured by the `Timer` constructor. A traditional function would lose that context when detached this way unless it was explicitly bound.
5657

5758
### Using arrow functions in array methods
5859

‎questions/can-you-offer-a-use-case-for-the-new-arrow-function-syntax-how-does-this-new-syntax-differ-from-other-functions/zh-CN.mdx‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ function Timer() {
4848
}
4949

5050
const timer = new Timer();
51-
timer.increment(); // 1
52-
timer.increment(); // 2
51+
const increment = timer.increment;
52+
increment(); // 1
53+
increment(); // 2
5354
```
5455

55-
在上面的例子中,在 `setInterval` 中使用传统函数需要额外的步骤来维护正确的 `this` 上下文。
56+
在上面的例子中,调用 `increment` 时没有将 `timer` 作为接收者,但箭头函数仍然使用 `Timer` 构造函数捕获的 `this`。如果使用传统函数,以这种方式脱离对象调用时会丢失该上下文,除非显式绑定它。
5657

5758
### 在数组方法中使用箭头函数
5859

‎questions/describe-the-difference-between-a-cookie-sessionstorage-and-localstorage/en-US.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Here's a table summarizing the 3 client storage mechanisms.
1818
| Lifespan | As specified | Until deleted | Until tab is closed |
1919
| Persistent across browser sessions | If a future expiry date is set | Yes | No |
2020
| Sent to server with every HTTP request | Yes, sent via `Cookie` header | No | No |
21-
| Total capacity (per domain) | 4KB | 5MB | 5MB |
21+
| Typical storage limit | About 4 KB per cookie | About 5 MB per origin (browser-dependent) | About 5 MB per origin (browser-dependent) |
2222
| Access | Across windows/tabs | Across windows/tabs | Same tab |
2323
| Security | JavaScript cannot access `HttpOnly` cookies | None | None |
2424

@@ -50,7 +50,7 @@ The following sections dive deeper into each client storage mechanism.
5050

5151
Cookies are used to store small pieces of data on the client side that can be sent back to the server with every HTTP request.
5252

53-
- **Storage capacity**: Limited to around 4KB for all cookies.
53+
- **Storage capacity**: Limited to around 4 KB per cookie. Browsers also limit how many cookies can be stored per domain.
5454
- **Lifespan**: Cookies can have a specific expiration date set using the `Expires` or `Max-Age` attributes. If no expiration date is set, the cookie is deleted when the browser is closed (session cookie).
5555
- **Access**: Cookies are domain-specific and can be shared across different pages and subdomains within the same domain.
5656
- **Security**: Cookies can be marked as `HttpOnly` to prevent access from JavaScript, reducing the risk of XSS attacks. They can also be secured with the `Secure` flag to ensure they are sent only when HTTPS is used.

‎questions/describe-the-difference-between-a-cookie-sessionstorage-and-localstorage/pt-BR.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Cookies, `localStorage`, and `sessionStorage`, são todos:
2424
| Vencimento | Definir manualmente | Para sempre | Ao fechar a aba |
2525
| Persistente através de sessões do navegador | Depende se a expiração está definida | Sim | Não |
2626
| Enviado para o servidor com cada solicitação HTTP | Os cookies são automaticamente enviados via cabeçalho `Cookie` | Não | Não |
27-
| Capacidade (por domínio) | 4kb | 5MB | 5MB |
27+
| Limite típico de armazenamento | Cerca de 4 KB por cookie | Cerca de 5 MB por origem (varia conforme o navegador) | Cerca de 5 MB por origem (varia conforme o navegador) |
2828
| Acesso | Quqlquer Janela | Quqlquer Janela | Mesma Guia |
2929

3030
Também existem outros mecanismos de armazenamento do lado do cliente, como [IndexedDB](https://developer.mozilla.org/en-US/docs/Web/API/IndexedDB_API) que é mais poderoso do que as tecnologias acima mencionadas, mas mais complicado de usar.

‎questions/describe-the-difference-between-a-cookie-sessionstorage-and-localstorage/zh-CN.mdx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ title: 描述浏览器中 cookie、`sessionStorage` 和 `localStorage` 之间的
1818
| 寿命 | 如指定 | 直到删除 | 直到选项卡关闭 |
1919
| 是否跨浏览器会话持久 | 如果设置了未来的过期日期 | 是 | 否 |
2020
| 是否随每个 HTTP 请求发送到服务器 | 是,通过 `Cookie` 标头发送 | 否 | 否 |
21-
| 总容量(每个域) | 4kb | 5MB | 5MB |
21+
| 典型存储限制 | 每个 cookie 约 4 KB | 每个来源约 5 MB(因浏览器而异) | 每个来源约 5 MB(因浏览器而异) |
2222
| 访问 | 跨窗口/选项卡 | 跨窗口/选项卡 | 相同选项卡 |
2323
| 安全性 | JavaScript 无法访问 `HttpOnly` cookies | 无 | 无 |
2424

@@ -50,7 +50,7 @@ Cookies、`localStorage` 和 `sessionStorage` 都是客户端(Web 浏览器)
5050

5151
Cookies 用于在客户端存储小块数据,这些数据可以通过每个 HTTP 请求发送回服务器。
5252

53-
- **存储容量**:所有 cookies 限制在 4KB 左右。
53+
- **存储容量**:每个 cookie 限制在 4 KB 左右。浏览器还会限制每个域可存储的 cookie 数量。
5454
- **寿命**:Cookies 可以使用 `Expires` 或 `Max-Age` 属性设置特定的过期日期。如果未设置过期日期,则在浏览器关闭时删除 cookie(会话 cookie)。
5555
- **访问**:Cookies 是特定于域的,可以在同一域内的不同页面和子域之间共享。
5656
- **安全性**:Cookies 可以标记为 `HttpOnly` 以防止从 JavaScript 访问,从而降低 XSS 攻击的风险。它们也可以使用 `Secure` 标志进行保护,以确保仅在使用 HTTPS 时发送它们。

‎questions/explain-the-concept-of-code-coverage-and-how-it-can-be-used-to-assess-test-quality/zh-CN.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,5 @@ jest --coverage
8282
## 延伸阅读
8383

8484
- [Istanbul documentation](https://istanbul.js.org/)
85-
- [Jest code coverage](https://jestjs.io/docs/en/coverage)
85+
- [Jest code coverage](https://jestjs.io/docs/cli#--coverageboolean)
8686
- [Karma coverage](https://karma-runner.github.io/6.3/intro/installation.html)

‎questions/explain-the-concept-of-error-propagation-in-javascript/zh-CN.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ async function b() {
102102

103103
- [MDN Web Docs: Error handling](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Control_flow_and_error_handling#exception_handling_statements)
104104
- [JavaScript.info: Error handling, "try...catch"](https://javascript.info/try-catch)
105-
- [Node.js Error Handling Best Practices](https://nodejs.dev/learn/error-handling-in-nodejs)
105+
- [Node.js Documentation: Errors](https://nodejs.org/api/errors.html)

‎questions/how-can-you-implement-secure-authentication-and-authorization-in-javascript-applications/en-US.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,5 +114,5 @@ app.get('/admin', checkRole('admin'), (req, res) => {
114114

115115
- [JWT.io](https://jwt.io/)
116116
- [Passport.js documentation](https://www.passportjs.org/docs/)
117-
- [OWASP Secure Coding Practices-Quick Reference Guide](https://owasp.org/www-project-secure-coding-practices-quick-reference-guide/)
117+
- [OWASP Authentication Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)
118118
- [MDN Web Docs on HTTP Strict Transport Security (HSTS)](https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security)

‎questions/how-can-you-implement-secure-authentication-and-authorization-in-javascript-applications/zh-CN.mdx‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,6 @@ app.get('/admin', checkRole('admin'), (req, res) => {
113113
## 延伸阅读
114114

115115
- [JWT.io](https://jwt.io/)
116-
- [Passport.js documentation](http://www.passportjs.org/docs/)
117-
- [OWASP Secure Coding Practices-Quick Reference Guide](https://owasp.org/www-project-secure-coding-practices-quick-reference-guide/)
118-
- [MDN Web Docs on HTTPS](https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security)
116+
- [Passport.js documentation](https://www.passportjs.org/docs/)
117+
- [OWASP Authentication Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Authentication_Cheat_Sheet.html)
118+
- [MDN Web Docs on HTTP Strict Transport Security (HSTS)](https://developer.mozilla.org/en-US/docs/Web/Security/HTTP_strict_transport_security)

0 commit comments

Comments
 (0)