write-concept by leonardomso/33-js-concepts
npx skills add https://github.com/leonardomso/33-js-concepts --skill write-concept在编写或改进 33 JavaScript Concepts 项目的概念文档页面时使用此技能。
/docs/concepts/ 中创建新的概念页面请记住:读者可能是从未编写过代码或正在学习 JavaScript 的人。写作时要对初学者抱有同理心,同时仍为中级开发者提供深度。让复杂主题变得易于理解,不要在没有链接到先决知识的情况下假设读者已有相关知识。
你的写作必须听起来像人写的,而不是 AI 生成的。以下是需要避免的具体模式:
| ❌ 避免 | ✓ 使用替代 |
|---|---|
| "掌握 [概念]" | "学习 [概念]" |
| "极大地更容易/更好" | "容易得多" 或 "更简洁" |
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
| "一个基本的东西" | "一个简单的东西" |
| "最重要的概念之一" | "这是一个重要的概念" |
| "要点" | "需要记住的关键点" |
| "深入理解 X 能改进" | "了解 X 能让 Y 更容易" |
| "要真正理解" | "让我们看看" 或 "方法如下" |
| "这很关键" | "这常常让人困惑" |
| "值得注意的是" | 直接陈述事情 |
| "记住这一点很重要" | "别忘了:" 或 "记住:" |
| "为了" | "为了" |
| "由于...的事实" | "因为" |
| "归根结底" | 完全删除 |
| "当涉及到" | 删除或重新表述 |
| "在本节中,我们将" | 直接开始解释 |
| "如前所述" | 删除或链接到相关部分 |
不要重复使用相同的引导模式。变化你的强调方式:
| 代替重复... | 变化使用... |
|---|---|
| "关键见解:" | "别忘了:"、"模式:"、"重点是:" |
| "最佳实践:" | "专业提示:"、"快速检查:"、"好习惯:" |
| "重要:" | "注意:"、"提醒:"、"注意:" |
| "记住:" | "记住:"、"规则:"、"这样想:" |
AI 生成的文本过度使用破折号。限制其使用,优先使用句号、逗号或冒号:
| ❌ 破折号过度使用 | ✓ 更好的替代 |
|---|---|
| "async/await — 语法糖..." | "async/await。它是语法糖..." |
| "理解 Promises — async/await 是构建..." | "理解 Promises。async/await 是构建..." |
| "不抛出错误 — 你只会得到..." | "不抛出错误。你只会得到..." |
| "在 async 函数之外 — 但只在..." | "在 async 函数之外,但只在..." |
| "快速失败 — 如果任何 Promise 拒绝..." | "快速失败。如果任何 Promise 拒绝..." |
| "实现相同的事情 — 选择..." | "实现相同的事情。选择..." |
何时可以接受使用破折号:
经验法则: 如果在 1500 字的文档中,除了结构化部分外,有超过 10-15 个破折号,那就是过度使用了。写作后,搜索 "—" 并评估每一个。
避免不增加信息的模糊最高级:
| ❌ 避免 | ✓ 使用替代 |
|---|---|
| "极大地" | "非常" 或完全删除 |
| "根本上" | "简单来说" 或具体说明什么方面是根本的 |
| "难以置信地" | 删除或具体说明 |
| "极其" | 删除或具体说明 |
| "绝对" | 删除 |
| "基本上" | 删除(如果需要这个词,说明解释不够清晰) |
| "本质上" | 删除或直接解释 |
| "非常" | 删除或使用更强的词 |
| "真的" | 删除 |
| "实际上" | 删除(除非纠正误解) |
| "事实上" | 删除(直接陈述事实) |
| "有趣的是" | 删除(让读者决定是否有趣) |
用对话式替代方案替换正式的学术风格短语:
| ❌ 生硬 | ✓ 对话式 |
|---|---|
| "应当注意" | "注意" 或直接陈述 |
| "人们可能想知道" | "你可能想知道" |
| "这使得开发者能够" | "这让你能够" |
| "上述的" | "这个" 或再次命名 |
| "随后" | "然后" 或 "接下来" |
| "利用" | "使用" |
| "开始" | "开始" |
| "在...之前" | "在...之前" |
| "在...的情况下" | "如果" |
| "相当数量的" | "很多" 或 "许多" |
偶尔添加人性化的点缀,让内容感觉不那么机械化,但不要过度:
// ✓ 好:每个部分一个俏皮评论
// 回调地狱 - 嵌套得如此之深,你需要手电筒
// ✓ 好:对话式旁白
// forEach 和 async 配合不好 — 它只是触发后就忘了:
// ✓ 好:相关的挫败感
// 终于,不会让你想掀桌子的错误处理。
// ❌ 坏:太刻意了
// 回调地狱 - 就像俄罗斯套娃和意大利面怪物生了孩子!🍝
// ❌ 坏:强制的幽默
// 让我们深入探索 Promises 的奇妙世界!🎉🚀
指南:
每个概念页面必须严格按照此顺序遵循此结构:
---
title: "概念名称:[钩子] in JavaScript"
sidebarTitle: "概念名称:[钩子]"
description: "SEO友好的描述,150-160字符,以动作词开头"
---
[开篇钩子 - 以让读者好奇的吸引人的问题开始]
[示例:"JavaScript如何从服务器获取数据?如何加载用户资料、提交表单或从API获取最新帖子?"]
[立即展示演示概念的简单代码示例]
```javascript
// 这是在JavaScript中[做某事]的方法
const example = doSomething()
console.log(example) // 预期输出
[简要解释与将要学习的内容的连接,并为关键术语添加**内联MDN链接**]
[核心解释,为任何新引入的术语/API添加内联MDN链接]
[可选:包含此部分MDN参考链接的CardGroup]
[相关的现实世界类比,让概念变得清晰]
[可视化概念的ASCII艺术图]
┌─────────────────────────────────────────────────────────────────────────┐
│ 图表标题 │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ [概念的可视化表示] │
│ │
└─────────────────────────────────────────────────────────────────────────┘
[深入探讨,包含代码示例、表格和Mintlify组件]
[如何在代码中实际使用该概念]
// 带有逐步注释的基本示例
// 步骤1:做这个
const step1 = something()
// 步骤2:然后做这个
const step2 = somethingElse(step1)
// 步骤3:最后
console.log(step2) // 预期输出
// 更复杂的现实世界示例
[突出开发者最常犯的错误]
┌─────────────────────────────────────────────────────────────────────────┐
│ 视觉比较 │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ 错误方式 正确方式 │
│ ───────── ───────── │
│ • 问题1 • 解决方案1 │
│ • 问题2 • 解决方案2 │
│ │
└─────────────────────────────────────────────────────────────────────────┘
// ❌ 错误 - 解释为什么这是错的
const bad = wrongApproach()
// ✓ 正确 - 解释正确的方法
const good = correctApproach()
[现实世界模式和最佳实践]
// 具有实际应用的可重用模式
async function realWorldExample() {
// 实现
}
// 用法
const result = await realWorldExample()
第一个关键点 — 简要解释
第二个关键点 — 简要解释
第三个关键点 — 简要解释
第四个关键点 — 简要解释
第五个关键点 — 简要解释
[目标是8-10个总结一切的关键要点]
[清晰的解释]
```javascript
// 演示答案的代码示例
[如果需要,提供清晰的解释和代码]
[目标是5-6个涵盖主要主题的问题]
* * *
## 相关概念
* * *
## 参考
## 文章
## 视频
* * *
## SEO指南
SEO(搜索引擎优化)对这个项目**至关重要**。每个概念页面应该针对开发者搜索该概念的各种方式排名。我们的目标是出现在以下查询的搜索结果中:
* "what is [概念] in JavaScript"
* "how does [概念] work in JavaScript"
* "[概念] JavaScript explained"
* "[概念] JavaScript tutorial"
* "JavaScript [概念] example"
每个写作决策——从标题到结构到词语选择——都应该考虑搜索意图。
* * *
### 每个概念的目标关键词
每个概念页面针对一个**关键词集群**——相关的搜索查询家族。在写作前,为你的概念识别这些:
关键词类型 | 模式 | 示例(DOM)
---|---|---
**主要** | [概念] + JavaScript | "DOM JavaScript", "JavaScript DOM"
**什么是** | what is [概念] in JavaScript | "what is the DOM in JavaScript"
**如何工作** | how does [概念] work | "how does the DOM work in JavaScript"
**如何做** | how to [动作] with [概念] | "how to manipulate the DOM"
**教程** | [概念] tutorial/guide/explained | "DOM tutorial JavaScript"
**比较** | [概念] vs [相关] | "DOM vs virtual DOM"
**更多关键词集群示例:**
* * *
### 标题标签优化
frontmatter中有**两个标题字段**:
* `title` — 页面的`<title>`标签(SEO,出现在搜索结果中)
* `sidebarTitle` — 侧边栏导航文本(更简洁,没有"JavaScript",因为我们在JS网站上)
**双标题模式:**
```markdown
---
title: "Closures: How Functions Remember Their Scope in JavaScript"
sidebarTitle: "Closures: How Functions Remember Their Scope"
---
title 以"in JavaScript"结尾,用于SEO关键词放置sidebarTitle 省略"JavaScript",用于更简洁的导航规则:
title的理想长度(Google会截断更长的标题)有效的标题公式:
title: "[概念]: [你将理解什么] in JavaScript"
sidebarTitle: "[概念]: [你将理解什么]"
title: "[概念]: [好处或结果] in JavaScript"
sidebarTitle: "[概念]: [好处或结果]"
标题示例:
| ❌ 差 | ✓ title(SEO) | ✓ sidebarTitle(导航) |
|---|---|---|
"Closures" | "Closures: How Functions Remember Their Scope in JavaScript" | "Closures: How Functions Remember Their Scope" |
"DOM" | "DOM: How Browsers Represent Web Pages in JavaScript" | "DOM: How Browsers Represent Web Pages" |
"Promises" | "Promises: Handling Async Operations in JavaScript" | "Promises: Handling Async Operations" |
"Call Stack" | "Call Stack: How Function Execution Works in JavaScript" | "Call Stack: How Function Execution Works" |
"Event Loop" | "Event Loop: How Async Code Actually Runs in JavaScript" | "Event Loop: How Async Code Actually Runs" |
"Scope" | "Scope and Closures: Variable Visibility in JavaScript" | "Scope and Closures: Variable Visibility" |
"this" | "this: How Context Binding Works in JavaScript" | "this: How Context Binding Works" |
"Prototype" | "Prototype Chain: Understanding Inheritance in JavaScript" | "Prototype Chain: Understanding Inheritance" |
字符数检查: 在最终确定前,验证你的title长度:
description字段成为元描述——用户在搜索结果中看到的片段。引人注目的描述能提高点击率。
规则:
描述公式:
[动作词] [概念是什么] in JavaScript. [他们将学习的具体内容]: [主题1], [主题2], 和 [主题3].
描述示例:
| 概念 | ❌ 太短(低点击率) | ✓ SEO优化(150-160字符) |
|---|---|---|
| DOM | "Understanding the DOM" | "Learn how the DOM works in JavaScript. Understand how browsers represent HTML as a tree, select and manipulate elements, traverse nodes, and optimize rendering." |
| Closures | "Functions that remember" | "Learn JavaScript closures and how functions remember their scope. Covers lexical scoping, practical use cases, memory considerations, and common closure patterns." |
| Promises | "Async JavaScript" | "Understand JavaScript Promises for handling asynchronous operations. Learn to create, chain, and combine Promises, handle errors properly, and write cleaner async code." |
| Event Loop | "How async works" | "Discover how the JavaScript event loop manages async code execution. Understand the call stack, task queue, microtasks, and why JavaScript is single-threaded but non-blocking." |
| Call Stack | "Function execution" | "Learn how the JavaScript call stack tracks function execution. Understand stack frames, execution context, stack overflow errors, and how recursion affects the stack." |
| this | "Understanding this" | "Learn the 'this' keyword in JavaScript and how context binding works. Covers the four binding rules, arrow function behavior, and how to use call, apply, and bind." |
字符数检查:
关键词必须出现在战略位置——但总是要自然。关键词堆砌会损害排名。
优先放置位置:
| 优先级 | 位置 | 如何包含 |
|---|---|---|
| 🔴 关键 | 标题 | 主要关键词在前半部分 |
| 🔴 关键 | 元描述 | 主要关键词 + 1-2个次要关键词 |
| 🔴 关键 | 第一段 | 在前100个词内自然提及 |
| 🟠 高 | H2标题 | 包含关键词的问题格式标题 |
| 🟠 高 | "你将学习什么"框 | 与主题相关的短语 |
| 🟡 中 | H3子标题 | 相关关键词和概念 |
| 🟡 中 | 关键要点 | 自然地强化主要关键词 |
| 🟢 好 | Alt文本 | 如果使用图片,包含关键词 |
示例:DOM页面的关键词放置
---
title: "DOM: How Browsers Represent Web Pages in JavaScript" ← 🔴 主要:"in JavaScript"在结尾
sidebarTitle: "DOM: How Browsers Represent Web Pages" ← 侧边栏:没有"JavaScript"
description: "Learn how the DOM works in JavaScript. Understand ← 🔴 主要:"DOM works in JavaScript"
how browsers represent HTML as a tree, select and manipulate ← 🔴 次要:"manipulate elements"
elements, traverse nodes, and optimize rendering."
---
How does JavaScript change what you see on a webpage? ← 钩子问题
The **Document Object Model (DOM)** is a programming interface ← 🔴 主要关键词在第一段
for web documents. It represents your HTML as a **tree of
objects** that JavaScript can read and manipulate.
<Info>
**What you'll learn in this guide:** ← 🟠 主题强化
- What the DOM actually is
- How to select elements (getElementById vs querySelector) ← 次要关键词
- How to traverse the DOM tree
- How to create, modify, and remove elements ← 隐式"DOM"
- How browsers render the DOM (Critical Rendering Path)
</Info>
## What is the DOM in JavaScript? ← 🟠 H2带问题关键词
The DOM (Document Object Model) is... ← 自然重复
## How the DOM Works ← 🟠 H2带"how"关键词
## DOM Manipulation Methods ← 🟡 H3带相关关键词
## Key Takeaways ← 🟡 在总结中强化
关键词堆砌的警告信号:
Google对直接回答用户查询的页面进行排名。构建你的内容以立即满足搜索意图。
第一段规则:
任何H2之后的第一段应该直接回答隐含的问题。不要铺垫到答案——直接给出答案。
<!-- ❌ 差:铺垫到答案 -->
## What is the Event Loop?
Before we can understand the event loop, we need to talk about JavaScript's
single-threaded nature. You see, JavaScript can only do one thing at a time,
and this creates some interesting challenges. The way JavaScript handles
this is through something called... the event loop.
<!-- ✓ 好:立即回答 -->
## What is the Event Loop?
The **event loop** is JavaScript's mechanism for executing code, handling events,
and managing asynchronous operations. It continuously monitors the call stack
and task queue, moving queued callbacks to the stack when it's empty — this is
how JavaScript handles async code despite being single-threaded.
问题格式的H2标题:
使用与人们搜索方式匹配的H2:
| 搜索查询 | 使用的H2 |
|---|---|
| "what is the DOM" | ## What is the DOM? |
| "how closures work" | ## How Do Closures Work? |
| "why use promises" | ## Why Use Promises? |
| "when to use async await" | ## When Should You Use async/await? |
特色片段出现在零位置——在所有有机结果之上。构建你的内容以赢得它们。
片段类型和如何赢得它们:
┌─────────────────────────────────────────────────────────────────────────┐
│ 特色片段类型 │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ 查询类型 片段格式 你的内容结构 │
│ ─────────── ────────────── ───────────────────────── │
│ │
│ "What is X" 段落 40-60词的定义 │
│ 紧接在H2之后 │
│ │
│ "How to X" 编号列表 <Steps>组件或 │
│ 编号的Markdown列表 │
│ │
│ "X vs Y" 表格 带有清晰列标题的 │
│ 比较表格 │
│ │
│ "Types of X" 项目符号列表 描述性H2下的 │
│ 项目符号列表 │
│ │
│ "[X] examples" 项目符号列表或 带有简要解释的 │
│ 代码块 代码示例 │
│ │
└─────────────────────────────────────────────────────────────────────────┘
模式1:定义片段(40-60词)
针对"what is [概念]"查询:
## What is a Closure in JavaScript?
A **closure** is a function that retains access to variables from its outer
(enclosing) scope, even after that outer function has finished executing.
Closures are created every time a function is created in JavaScript, allowing
inner functions to "remember" and access their lexical environment.
为什么这能赢:
模式2:列表片段(步骤)
针对"how to [动作]"查询:
## How to Make a Fetch Request in JavaScript
<Steps>
<Step title="1. Call fetch() with the URL">
The `fetch()` function takes a URL and returns a Promise that resolves to a Response object.
</Step>
<Step title="2. Check if the response was successful">
Always verify `response.ok` before processing — fetch doesn't throw on HTTP errors.
</Step>
<Step title="3. Parse the response body">
Use `response.json()` for JSON data, `response.text()` for plain text.
</Step>
<Step title="4. Handle errors properly">
Wrap everything in try/catch to handle both network and HTTP errors.
</Step>
</Steps>
模式3:表格片段(比较)
针对"[X] vs [Y]"查询:
## == vs === in JavaScript
| Aspect | `==` (Loose Equality) | `===` (Strict Equality) |
|--------|----------------------|------------------------|
| Type coercion | Yes — converts types before comparing | No — types must match |
| Speed | Slower (coercion overhead) | Faster (no coercion) |
| Predictability | Can produce surprising results | Always predictable |
| Recommendation | Avoid in most cases | Use by default |
```javascript
// Examples
5 == "5" // true (string coerced to number)
5 === "5" // false (different types)
模式4:列表片段(类型/类别)
针对"types of [概念]"查询:
## Types of Scope in JavaScript
JavaScript has three types of scope that determine where variables are accessible:
- **Global Scope** — Variables declared outside any function or block; accessible everywhere
- **Function Scope** — Variables declared inside a function with `var`; accessible only within that function
- **Block Scope** — Variables declared with `let` or `const` inside `{}`; accessible only within that block
你构建内容的方式既影响排名又影响用户体验。
倒金字塔结构:
把最重要的信息放在前面。搜索引擎和用户都喜欢立即回答问题的内容。
┌─────────────────────────────────────────────────────────────────────────┐
│ 倒金字塔结构 │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ │
│ ┌─────────────────────────────────────┐ │
│ │ 回答问题 │ ← 前100词 │
│ │ 定义 + 核心概念 │ (最重要的) │
│ └──────────────────┬──────────────────┘ │
│ │ │
│ ┌────────────────┴────────────────┐ │
│ │ 解释工作原理 │ ← 接下来300词 │
│ │ 机制 + 可视化图表 │ (支持信息) │
│ └────────────────┬─────────────────┘ │
│ │ │
│ ┌──────────────────┴──────────────────┐ │
│ │ 展示实际示例 │ ← 代码示例 │
│ │ 代码 + 逐步说明 │ (证明有效) │
│ └──────────────────┬──────────────────┘ │
│ │ │
│ ┌──────────────────────┴──────────────────────┐ │
│ │ 覆盖边缘情况 │ ← 高级 │
│ │ 常见错误、陷阱 │ (深度) │
│ └──────────────────────┬──────────────────────┘ │
│ │ │
│ ┌──────────────────────────┴──────────────────────────┐ │
│ │ 额外资源 │ ← 外部 │
│ │ 相关概念、文章、视频 │ (链接) │
│ └──────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
可扫描的内容模式:
Google偏爱易于扫描的内容。使用这些元素:
| 元素 | SEO好处 | 何时使用 |
|---|---|---|
| 短段落 | 降低跳出率 | 总是(最多2-4句) |
| 项目符号列表 | 常成为特色片段 | 3个以上项目时 |
| 编号列表 | "如何做"片段潜力 | 顺序步骤时 |
| 表格 | 高片段潜力 | 比较、参考数据时 |
| 粗体文本 | 为爬虫突出关键词 | 关键术语首次提及时 |
| 标题(H2/H3) | 向Google发送结构信号 | 每个主要主题转换时 |
内容长度指南:
| 长度 | 评估 | 行动 |
|---|---|---|
| 少于1,000词 | 太薄 | 添加更多深度、示例、边缘情况 |
| 1,000-1,500词 | 最小可行 | 简单概念可接受 |
| 1,500-2,500词 | 好 | 大多数概念页面的标准 |
| 2,500-4,000词 | 优秀 | 全面指南的理想长度 |
| 超过4,000词 | 评估 | 考虑拆分为多个页面 |
注意: 仅长度不能保证排名。每个部分都必须增加价值——不要填充内容。
内部链接帮助搜索引擎理解你的网站结构并分配页面权威。
主题集群策略:
将概念页面视为一个相互连接的网络。每个概念应该链接到3-5个相关概念:
┌─────────────────┐
┌───────│ Promises │───────┐
│ └────────┬────────┘ │
│ │ │
▼ ▼ ▼
┌───────────┐ ┌───────────────┐ ┌─────────────┐
│async/await│◄──►│ Event Loop │◄──►│ Callbacks │
└───────────┘ └───────────────┘ └─────────────┘
│ │ │
│ ▼ │
│ ┌───────────────┐ │
└──────►│ Call Stack │◄───────┘
└───────────────┘
链接放置指南:
<Warning>
**Prerequisite:** This guide assumes you understand [Promises](/concepts/promises) and the [Event Loop](/concepts/event-loop). Read those first if you're not comfortable with asynchronous JavaScript.
</Warning>
When the callback finishes, it's added to the task queue — which is managed by the [event loop](/concepts/event-loop).
<CardGroup cols={2}>
<Card title="Promises" icon="handshake" href="/concepts/promises">
async/await is built on top of Promises
</Card>
<Card title="Event Loop" icon="arrows-spin" href="/concepts/event-loop">
How JavaScript manages async operations
</Card>
</CardGroup>
锚文本最佳实践:
| ❌ 差的锚文本 | ✓ 好的锚文本 | 原因 |
|---|---|---|
| "点击这里" | "event loop指南" | 描述性,包含关键词 |
| "这篇文章" | "我们的Promises概念" | 告诉Google页面内容 |
| "这里" | "JavaScript闭包" | 锚文本中的关键词 |
| "阅读更多" | "理解调用栈" | 自然、信息丰富 |
URL(slug)是一个次要但有意义的排名因素。
规则:
closures 而不是 Closurescall-stack 而不是 call_stack 或 callstackSlug示例:
| 概念 | ❌ 避免 | ✓ 使用 |
|---|---|---|
| The Event Loop | the-event-loop | event-loop |
| this, call, apply and bind | this-call-apply-and-bind | this-call-apply-bind |
| Scope and Closures | scope-and-closures | scope-and-closures(可接受)或 scope-closures |
| DOM and Layout Trees | dom-and-layout-trees | dom 或 dom-layout-trees |
注意: 对于这个项目,slug已经设置好了。创建新页面时,遵循这些约定。
开篇段落是SEO的黄金地段。它应该:
模板:
[匹配搜索意图的问题钩子?] [也许另一个问题?]
**[主要关键词]** 是[回答"什么是X"的简要定义]。
[解释为什么重要或它实现什么的一句话]。
```javascript
// 立即展示一个简单示例
[简要过渡到"你将学习什么"框]
示例(闭包):
为什么有些函数似乎"记住"了应该已经消失的变量?
回调如何仍然能访问早已完成运行的函数中的变量?
答案是**闭包**——JavaScript最强大(也最常被误解)的特性之一。闭包是一个函数,即使在其外部作用域执行完毕后,仍保留对其外部作用域变量的访问权限。
```javascript
function createCounter() {
let count = 0 // 这个变量被返回的函数"封闭"
return function() {
count++
return count
}
}
const counter = createCounter()
console.log(counter()) // 1
console.log(counter()) // 2 — 它记住了!
理解闭包解锁了像私有变量、工厂函数和模块模式这样的模式,这些模式为现代JavaScript提供动力。
**为什么这对SEO有效:**
* 问题钩子匹配人们的搜索方式("为什么函数记得")
* 第一段中的粗体关键词
* 直接定义回答"什么是闭包"
* 代码示例立即演示
* 自然地设置学习目标
---
## 内联链接规则(关键!)
### 总是链接到MDN
每当引入新的Web API、方法、对象或JavaScript概念时,**立即链接到MDN**。这为读者提供了深入学习路径。
```markdown
<!-- ✓ 正确:首次提及时链接 -->
The **[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)** is JavaScript's modern way to make network requests.
The **[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)** object contains everything about the server's reply.
Most modern APIs return data in **[JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)** format.
<!-- ❌ 错误:没有链接 -->
The Fetch API is JavaScript's modern way to make network requests.
当提到其他页面中涵盖的概念时,链接到它们:
<!-- ✓ 正确:链接到相关概念的内部链接 -->
If you're not familiar with it, check out our [async/await concept](/concepts/async-await) first.
This guide assumes you understand [Promises](/concepts/promises).
<!-- ❌ 错误:没有内部链接 -->
If you're not familiar with async/await, you should learn that first.
| 概念 | MDN URL模式 |
|---|---|
| Web APIs | https://developer.mozilla.org/en-US/docs/Web/API/{APIName} |
| JavaScript对象 | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/{Object} |
| HTTP | https://developer.mozilla.org/en-US/docs/Web/HTTP |
| HTTP方法 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/{METHOD} |
| HTTP头部 | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers |
// ✓ 好:从绝对基础开始
// 这是在JavaScript中获取数据的方法
const response = await fetch('https://api.example.com/users/1')
const user = await response.json()
console.log(user.name) // "Alice"
// 步骤1:fetch()返回一个解析为Response对象的Promise
const responsePromise = fetch('https://api.example.com/users')
// 步骤2:当响应到达时,我们得到一个Response对象
responsePromise.then(response => {
console.log(response.status) // 200
// 步骤3:主体是一个流,我们需要解析它
return response.json()
})
.then(data => {
// 步骤4:现在我们有了实际数据
console.log(data)
})
const greeting = "Hello"
console.log(typeof greeting) // "string"
const numbers = [1, 2, 3]
console.log(numbers.length) // 3
// ❌ 错误 - 这漏掉了HTTP错误!
try {
const response = await fetch('/api/users/999')
const data = await response.json()
} catch (error) {
// 只捕获网络错误,不捕获404!
}
// ✓ 正确 - 检查response.ok
try {
const response = await fetch('/api/users/999')
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`)
}
const data = await response.json()
} catch (error) {
// 现在同时捕获网络和HTTP错误
}
// ❌ 差
const x = [1, 2,
Use this skill when writing or improving concept documentation pages for the 33 JavaScript Concepts project.
/docs/concepts/Remember: the reader might be someone who has never coded before or is just learning JavaScript. Write with empathy for beginners while still providing depth for intermediate developers. Make complex topics feel approachable and never assume prior knowledge without linking to prerequisites.
Your writing must sound human, not AI-generated. Here are specific patterns to avoid:
| ❌ Avoid | ✓ Use Instead |
|---|---|
| "Master [concept]" | "Learn [concept]" |
| "dramatically easier/better" | "much easier" or "cleaner" |
| "one fundamental thing" | "one simple thing" |
| "one of the most important concepts" | "This is a big one" |
| "essential points" | "key things to remember" |
| "understanding X deeply improves" | "knowing X well makes Y easier" |
| "To truly understand" | "Let's look at" or "Here's how" |
| "This is crucial" | "This trips people up" |
| "It's worth noting that" | Just state the thing directly |
| "It's important to remember" | "Don't forget:" or "Remember:" |
| "In order to" | "To" |
| "Due to the fact that" | "Because" |
| "At the end of the day" | Remove entirely |
| "When it comes to" | Remove or rephrase |
| "In this section, we will" | Just start explaining |
Don't use the same lead-in pattern repeatedly. Vary your emphasis:
| Instead of repeating... | Vary with... |
|---|---|
| "Key insight:" | "Don't forget:", "The pattern:", "Here's the thing:" |
| "Best practice:" | "Pro tip:", "Quick check:", "A good habit:" |
| "Important:" | "Watch out:", "Heads up:", "Note:" |
| "Remember:" | "Keep in mind:", "The rule:", "Think of it this way:" |
AI-generated text overuses em dashes. Limit their use and prefer periods, commas, or colons:
| ❌ Em Dash Overuse | ✓ Better Alternative |
|---|---|
| "async/await — syntactic sugar that..." | "async/await. It's syntactic sugar that..." |
| "understand Promises — async/await is built..." | "understand Promises. async/await is built..." |
| "doesn't throw an error — you just get..." | "doesn't throw an error. You just get..." |
| "outside of async functions — but only in..." | "outside of async functions, but only in..." |
| "Fails fast — if any Promise rejects..." | "Fails fast. If any Promise rejects..." |
| "achieve the same thing — the choice..." | "achieve the same thing. The choice..." |
When em dashes ARE acceptable:
Rule of thumb: If you have more than 10-15 em dashes in a 1500-word document outside of structured sections, you're overusing them. After writing, search for "—" and evaluate each one.
Avoid vague superlatives that add no information:
| ❌ Avoid | ✓ Use Instead |
|---|---|
| "dramatically" | "much" or remove entirely |
| "fundamentally" | "simply" or be specific about what's fundamental |
| "incredibly" | remove or be specific |
| "extremely" | remove or be specific |
| "absolutely" | remove |
| "basically" | remove (if you need it, you're not explaining clearly) |
| "essentially" | remove or just explain directly |
| "very" | remove or use a stronger word |
| "really" | remove |
| "actually" | remove (unless correcting a misconception) |
| "In fact" | remove (just state the fact) |
| "Interestingly" | remove (let the reader decide if it's interesting) |
Replace formal academic-style phrases with conversational alternatives:
| ❌ Stiff | ✓ Conversational |
|---|---|
| "It should be noted that" | "Note that" or just state it |
| "One might wonder" | "You might wonder" |
| "This enables developers to" | "This lets you" |
| "The aforementioned" | "this" or name it again |
| "Subsequently" | "Then" or "Next" |
| "Utilize" | "Use" |
| "Commence" | "Start" |
| "Prior to" | "Before" |
| "In the event that" | "If" |
| "A considerable amount of" | "A lot of" or "Many" |
Add occasional human touches to make the content feel less robotic, but don't overdo it:
// ✓ Good: One playful comment per section
// Callback hell - nested so deep you need a flashlight
// ✓ Good: Conversational aside
// forEach and async don't play well together — it just fires and forgets:
// ✓ Good: Relatable frustration
// Finally, error handling that doesn't make you want to flip a table.
// ❌ Bad: Trying too hard
// Callback hell - it's like a Russian nesting doll had a baby with a spaghetti monster! 🍝
// ❌ Bad: Forced humor
// Let's dive into the AMAZING world of Promises! 🎉🚀
Guidelines:
Every concept page MUST follow this structure in this exact order:
---
title: "Concept Name: [Hook] in JavaScript"
sidebarTitle: "Concept Name: [Hook]"
description: "SEO-friendly description in 150-160 characters starting with action word"
---
[Opening hook - Start with engaging questions that make the reader curious]
[Example: "How does JavaScript get data from a server? How do you load user profiles, submit forms, or fetch the latest posts from an API?"]
[Immediately show a simple code example demonstrating the concept]
```javascript
// This is how you [do the thing] in JavaScript
const example = doSomething()
console.log(example) // Expected output
[Brief explanation connecting to what they'll learn, with inline MDN links for key terms]
[Core explanation with inline MDN links for any new terms/APIs introduced]
[Optional: CardGroup with MDN reference links for this section]
[Relatable real-world analogy that makes the concept click]
[ASCII art diagram visualizing the concept]
┌─────────────────────────────────────────────────────────────────────────┐
│ DIAGRAM TITLE │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ [Visual representation of the concept] │
│ │
└─────────────────────────────────────────────────────────────────────────┘
[Deep dive with code examples, tables, and Mintlify components]
[How to actually use the concept in code]
// Basic example with step-by-step comments
// Step 1: Do this
const step1 = something()
// Step 2: Then this
const step2 = somethingElse(step1)
// Step 3: Finally
console.log(step2) // Expected output
// More complex real-world example
[Highlight the most common mistake developers make]
┌─────────────────────────────────────────────────────────────────────────┐
│ VISUAL COMPARISON │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ WRONG WAY RIGHT WAY │
│ ───────── ───────── │
│ • Problem 1 • Solution 1 │
│ • Problem 2 • Solution 2 │
│ │
└─────────────────────────────────────────────────────────────────────────┘
// ❌ WRONG - Explanation of why this is wrong
const bad = wrongApproach()
// ✓ CORRECT - Explanation of the right way
const good = correctApproach()
[Real-world patterns and best practices]
// Reusable pattern with practical application
async function realWorldExample() {
// Implementation
}
// Usage
const result = await realWorldExample()
First key point — Brief explanation
Second key point — Brief explanation
Third key point — Brief explanation
Fourth key point — Brief explanation
Fifth key point — Brief explanation
[Aim for 8-10 key takeaways that summarize everything]
[Clear explanation]
```javascript
// Code example demonstrating the answer
```
[Clear explanation with code if needed]
[Aim for 5-6 questions covering the main topics]
SEO (Search Engine Optimization) is critical for this project. Each concept page should rank for the various ways developers search for that concept. Our goal is to appear in search results for queries like:
Every writing decision — from title to structure to word choice — should consider search intent.
Each concept page targets a keyword cluster — the family of related search queries. Before writing, identify these for your concept:
| Keyword Type | Pattern | Example (DOM) |
|---|---|---|
| Primary | [concept] + JavaScript | "DOM JavaScript", "JavaScript DOM" |
| What is | what is [concept] in JavaScript | "what is the DOM in JavaScript" |
| How does | how does [concept] work | "how does the DOM work in JavaScript" |
| How to | how to [action] with [concept] | "how to manipulate the DOM" |
| Tutorial | [concept] tutorial/guide/explained | "DOM tutorial JavaScript" |
| Comparison | [concept] vs [related] | "DOM vs virtual DOM" |
More Keyword Cluster Examples:
The frontmatter has two title fields :
title — The page's <title> tag (SEO, appears in search results)sidebarTitle — The sidebar navigation text (cleaner, no "JavaScript" since we're on a JS site)The Two-Title Pattern:
---
title: "Closures: How Functions Remember Their Scope in JavaScript"
sidebarTitle: "Closures: How Functions Remember Their Scope"
---
title ends with "in JavaScript" for SEO keyword placementsidebarTitle omits "JavaScript" for cleaner navigationRules:
title (Google truncates longer titles)Title Formulas That Work:
title: "[Concept]: [What You'll Understand] in JavaScript"
sidebarTitle: "[Concept]: [What You'll Understand]"
title: "[Concept]: [Benefit or Outcome] in JavaScript"
sidebarTitle: "[Concept]: [Benefit or Outcome]"
Title Examples:
| ❌ Bad | ✓ title (SEO) | ✓ sidebarTitle (Navigation) |
|---|---|---|
"Closures" | "Closures: How Functions Remember Their Scope in JavaScript" | "Closures: How Functions Remember Their Scope" |
"DOM" | "DOM: How Browsers Represent Web Pages in JavaScript" | "DOM: How Browsers Represent Web Pages" |
"Promises" |
Character Count Check: Before finalizing, verify your title length:
The description field becomes the meta description — the snippet users see in search results. A compelling description increases click-through rate.
Rules:
Description Formula:
[Action word] [what the concept is] in JavaScript. [Specific things they'll learn]: [topic 1], [topic 2], and [topic 3].
Description Examples:
| Concept | ❌ Too Short (Low CTR) | ✓ SEO-Optimized (150-160 chars) |
|---|---|---|
| DOM | "Understanding the DOM" | "Learn how the DOM works in JavaScript. Understand how browsers represent HTML as a tree, select and manipulate elements, traverse nodes, and optimize rendering." |
| Closures | "Functions that remember" | "Learn JavaScript closures and how functions remember their scope. Covers lexical scoping, practical use cases, memory considerations, and common closure patterns." |
| Promises | "Async JavaScript" |
Character Count Check:
Keywords must appear in strategic locations — but always naturally. Keyword stuffing hurts rankings.
Priority Placement Locations:
| Priority | Location | How to Include |
|---|---|---|
| 🔴 Critical | Title | Primary keyword in first half |
| 🔴 Critical | Meta description | Primary keyword + 1-2 secondary |
| 🔴 Critical | First paragraph | Natural mention within first 100 words |
| 🟠 High | H2 headings | Question-format headings with keywords |
| 🟠 High | "What you'll learn" box | Topic-related phrases |
| 🟡 Medium | H3 subheadings | Related keywords and concepts |
| 🟡 Medium | Key Takeaways | Reinforce main keywords naturally |
| 🟢 Good | Alt text | If using images, include keywords |
Example: Keyword Placement for DOM Page
---
title: "DOM: How Browsers Represent Web Pages in JavaScript" ← 🔴 Primary: "in JavaScript" at end
sidebarTitle: "DOM: How Browsers Represent Web Pages" ← Sidebar: no "JavaScript"
description: "Learn how the DOM works in JavaScript. Understand ← 🔴 Primary: "DOM works in JavaScript"
how browsers represent HTML as a tree, select and manipulate ← 🔴 Secondary: "manipulate elements"
elements, traverse nodes, and optimize rendering."
---
How does JavaScript change what you see on a webpage? ← Hook question
The **Document Object Model (DOM)** is a programming interface ← 🔴 Primary keyword in first paragraph
for web documents. It represents your HTML as a **tree of
objects** that JavaScript can read and manipulate.
<Info>
**What you'll learn in this guide:** ← 🟠 Topic reinforcement
- What the DOM actually is
- How to select elements (getElementById vs querySelector) ← Secondary keywords
- How to traverse the DOM tree
- How to create, modify, and remove elements ← "DOM" implicit
- How browsers render the DOM (Critical Rendering Path)
</Info>
## What is the DOM in JavaScript? ← 🟠 H2 with question keyword
The DOM (Document Object Model) is... ← Natural repetition
## How the DOM Works ← 🟠 H2 with "how" keyword
## DOM Manipulation Methods ← 🟡 H3 with related keyword
## Key Takeaways ← 🟡 Reinforce in summary
Warning Signs of Keyword Stuffing:
Google ranks pages that directly answer the user's query. Structure your content to satisfy search intent immediately.
The First Paragraph Rule:
The first paragraph after any H2 should directly answer the implied question. Don't build up to the answer — lead with it.
<!-- ❌ BAD: Builds up to the answer -->
## What is the Event Loop?
Before we can understand the event loop, we need to talk about JavaScript's
single-threaded nature. You see, JavaScript can only do one thing at a time,
and this creates some interesting challenges. The way JavaScript handles
this is through something called... the event loop.
<!-- ✓ GOOD: Answers immediately -->
## What is the Event Loop?
The **event loop** is JavaScript's mechanism for executing code, handling events,
and managing asynchronous operations. It continuously monitors the call stack
and task queue, moving queued callbacks to the stack when it's empty — this is
how JavaScript handles async code despite being single-threaded.
Question-Format H2 Headings:
Use H2s that match how people search:
| Search Query | H2 to Use |
|---|---|
| "what is the DOM" | ## What is the DOM? |
| "how closures work" | ## How Do Closures Work? |
| "why use promises" | ## Why Use Promises? |
| "when to use async await" | ## When Should You Use async/await? |
Featured snippets appear at position zero — above all organic results. Structure your content to win them.
Snippet Types and How to Win Them:
┌─────────────────────────────────────────────────────────────────────────┐
│ FEATURED SNIPPET TYPES │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ QUERY TYPE SNIPPET FORMAT YOUR CONTENT STRUCTURE │
│ ─────────── ────────────── ───────────────────────── │
│ │
│ "What is X" Paragraph 40-60 word definition │
│ immediately after H2 │
│ │
│ "How to X" Numbered list <Steps> component or │
│ numbered Markdown list │
│ │
│ "X vs Y" Table Comparison table with │
│ clear column headers │
│ │
│ "Types of X" Bulleted list Bullet list under │
│ descriptive H2 │
│ │
│ "[X] examples" Bulleted list or Code examples with │
│ code block brief explanations │
│ │
└─────────────────────────────────────────────────────────────────────────┘
Pattern 1: Definition Snippet (40-60 words)
For "what is [concept]" queries:
## What is a Closure in JavaScript?
A **closure** is a function that retains access to variables from its outer
(enclosing) scope, even after that outer function has finished executing.
Closures are created every time a function is created in JavaScript, allowing
inner functions to "remember" and access their lexical environment.
Why this wins:
Pattern 2: List Snippet (Steps)
For "how to [action]" queries:
## How to Make a Fetch Request in JavaScript
<Steps>
<Step title="1. Call fetch() with the URL">
The `fetch()` function takes a URL and returns a Promise that resolves to a Response object.
</Step>
<Step title="2. Check if the response was successful">
Always verify `response.ok` before processing — fetch doesn't throw on HTTP errors.
</Step>
<Step title="3. Parse the response body">
Use `response.json()` for JSON data, `response.text()` for plain text.
</Step>
<Step title="4. Handle errors properly">
Wrap everything in try/catch to handle both network and HTTP errors.
</Step>
</Steps>
Pattern 3: Table Snippet (Comparison)
For "[X] vs [Y]" queries:
## == vs === in JavaScript
| Aspect | `==` (Loose Equality) | `===` (Strict Equality) |
|--------|----------------------|------------------------|
| Type coercion | Yes — converts types before comparing | No — types must match |
| Speed | Slower (coercion overhead) | Faster (no coercion) |
| Predictability | Can produce surprising results | Always predictable |
| Recommendation | Avoid in most cases | Use by default |
```javascript
// Examples
5 == "5" // true (string coerced to number)
5 === "5" // false (different types)
**Pattern 4: List Snippet (Types/Categories)**
For "types of [concept]" queries:
```mdx
## Types of Scope in JavaScript
JavaScript has three types of scope that determine where variables are accessible:
- **Global Scope** — Variables declared outside any function or block; accessible everywhere
- **Function Scope** — Variables declared inside a function with `var`; accessible only within that function
- **Block Scope** — Variables declared with `let` or `const` inside `{}`; accessible only within that block
How you structure content affects both rankings and user experience.
The Inverted Pyramid:
Put the most important information first. Search engines and users both prefer content that answers questions immediately.
┌─────────────────────────────────────────────────────────────────────────┐
│ THE INVERTED PYRAMID │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ │
│ ┌─────────────────────────────────────┐ │
│ │ ANSWER THE QUESTION │ ← First 100 words │
│ │ Definition + Core Concept │ (most important) │
│ └──────────────────┬──────────────────┘ │
│ │ │
│ ┌────────────────┴────────────────┐ │
│ │ EXPLAIN HOW IT WORKS │ ← Next 300 words │
│ │ Mechanism + Visual Diagram │ (supporting info) │
│ └────────────────┬─────────────────┘ │
│ │ │
│ ┌──────────────────┴──────────────────┐ │
│ │ SHOW PRACTICAL EXAMPLES │ ← Code examples │
│ │ Code + Step-by-step │ (proof it works) │
│ └──────────────────┬──────────────────┘ │
│ │ │
│ ┌──────────────────────┴──────────────────────┐ │
│ │ COVER EDGE CASES │ ← Advanced │
│ │ Common mistakes, gotchas │ (depth) │
│ └──────────────────────┬──────────────────────┘ │
│ │ │
│ ┌──────────────────────────┴──────────────────────────┐ │
│ │ ADDITIONAL RESOURCES │ ← External │
│ │ Related concepts, articles, videos │ (links) │
│ └──────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘
Scannable Content Patterns:
Google favors content that's easy to scan. Use these elements:
| Element | SEO Benefit | When to Use |
|---|---|---|
| Short paragraphs | Reduces bounce rate | Always (2-4 sentences max) |
| Bullet lists | Often become featured snippets | Lists of 3+ items |
| Numbered lists | "How to" snippet potential | Sequential steps |
| Tables | High snippet potential | Comparisons, reference data |
| Bold text | Highlights keywords for crawlers | First mention of key terms |
| Headings (H2/H3) | Structure signals to Google | Every major topic shift |
Content Length Guidelines:
| Length | Assessment | Action |
|---|---|---|
| Under 1,000 words | Too thin | Add more depth, examples, edge cases |
| 1,000-1,500 words | Minimum viable | Acceptable for simple concepts |
| 1,500-2,500 words | Good | Standard for most concept pages |
| 2,500-4,000 words | Excellent | Ideal for comprehensive guides |
| Over 4,000 words | Evaluate | Consider splitting into multiple pages |
Note: Length alone doesn't guarantee rankings. Every section must add value — don't pad content.
Internal links help search engines understand your site structure and distribute page authority.
Topic Cluster Strategy:
Think of concept pages as an interconnected network. Every concept should link to 3-5 related concepts:
┌─────────────────┐
┌───────│ Promises │───────┐
│ └────────┬────────┘ │
│ │ │
▼ ▼ ▼
┌───────────┐ ┌───────────────┐ ┌─────────────┐
│async/await│◄──►│ Event Loop │◄──►│ Callbacks │
└───────────┘ └───────────────┘ └─────────────┘
│ │ │
│ ▼ │
│ ┌───────────────┐ │
└──────►│ Call Stack │◄───────┘
└───────────────┘
Link Placement Guidelines:
<Warning>
**Prerequisite:** This guide assumes you understand [Promises](/concepts/promises) and the [Event Loop](/concepts/event-loop). Read those first if you're not comfortable with asynchronous JavaScript.
</Warning>
2. In Body Content (natural context):
When the callback finishes, it's added to the task queue — which is managed by the [event loop](/concepts/event-loop).
3. In Related Concepts Section:
<CardGroup cols={2}>
<Card title="Promises" icon="handshake" href="/concepts/promises">
async/await is built on top of Promises
</Card>
<Card title="Event Loop" icon="arrows-spin" href="/concepts/event-loop">
How JavaScript manages async operations
</Card>
</CardGroup>
Anchor Text Best Practices:
| ❌ Bad Anchor Text | ✓ Good Anchor Text | Why |
|---|---|---|
| "click here" | "event loop guide" | Descriptive, includes keyword |
| "this article" | "our Promises concept" | Tells Google what page is about |
| "here" | "JavaScript closures" | Keywords in anchor text |
| "read more" | "understanding the call stack" | Natural, informative |
URLs (slugs) are a minor but meaningful ranking factor.
Rules:
closures not Closurescall-stack not call_stack or callstackSlug Examples:
| Concept | ❌ Avoid | ✓ Use |
|---|---|---|
| The Event Loop | the-event-loop | event-loop |
| this, call, apply and bind | this-call-apply-and-bind | this-call-apply-bind |
| Scope and Closures | scope-and-closures | scope-and-closures (acceptable) or scope-closures |
Note: For this project, slugs are already set. When creating new pages, follow these conventions.
The opening paragraph is prime SEO real estate. It should:
Template:
[Question hook that matches search intent?] [Maybe another question?]
The **[Primary Keyword]** is [brief definition that answers "what is X"].
[One sentence explaining why it matters or what it enables].
```javascript
// Immediately show a simple example
[Brief transition to "What you'll learn" box]
**Example (Closures):**
```mdx
Why do some functions seem to "remember" variables that should have disappeared?
How can a callback still access variables from a function that finished running
long ago?
The answer is **closures** — one of JavaScript's most powerful (and often
misunderstood) features. A closure is a function that retains access to its
outer scope's variables, even after that outer scope has finished executing.
```javascript
function createCounter() {
let count = 0 // This variable is "enclosed" by the returned function
return function() {
count++
return count
}
}
const counter = createCounter()
console.log(counter()) // 1
console.log(counter()) // 2 — it remembers!
Understanding closures unlocks patterns like private variables, factory functions, and the module pattern that power modern JavaScript.
**Why this works for SEO:**
- Question hooks match how people search ("why do functions remember")
- Bold keyword in first paragraph
- Direct definition answers "what is a closure"
- Code example demonstrates immediately
- Natural setup for learning objectives
---
## Inline Linking Rules (Critical!)
### Always Link to MDN
Whenever you introduce a new Web API, method, object, or JavaScript concept, **link to MDN immediately**. This gives readers a path to deeper learning.
```mdx
<!-- ✓ CORRECT: Link on first mention -->
The **[Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)** is JavaScript's modern way to make network requests.
The **[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response)** object contains everything about the server's reply.
Most modern APIs return data in **[JSON](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON)** format.
<!-- ❌ WRONG: No links -->
The Fetch API is JavaScript's modern way to make network requests.
When mentioning concepts covered in other pages, link to them:
<!-- ✓ CORRECT: Internal links to related concepts -->
If you're not familiar with it, check out our [async/await concept](/concepts/async-await) first.
This guide assumes you understand [Promises](/concepts/promises).
<!-- ❌ WRONG: No internal links -->
If you're not familiar with async/await, you should learn that first.
| Concept | MDN URL Pattern |
|---|---|
| Web APIs | https://developer.mozilla.org/en-US/docs/Web/API/{APIName} |
| JavaScript Objects | https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/{Object} |
| HTTP | https://developer.mozilla.org/en-US/docs/Web/HTTP |
| HTTP Methods | https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/{METHOD} |
| HTTP Headers | https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers |
// ✓ GOOD: Start with the absolute basics
// This is how you fetch data in JavaScript
const response = await fetch('https://api.example.com/users/1')
const user = await response.json()
console.log(user.name) // "Alice"
// Step 1: fetch() returns a Promise that resolves to a Response object
const responsePromise = fetch('https://api.example.com/users')
// Step 2: When the response arrives, we get a Response object
responsePromise.then(response => {
console.log(response.status) // 200
// Step 3: The body is a stream, we need to parse it
return response.json()
})
.then(data => {
// Step 4: Now we have the actual data
console.log(data)
})
const greeting = "Hello"
console.log(typeof greeting) // "string"
const numbers = [1, 2, 3]
console.log(numbers.length) // 3
// ❌ WRONG - This misses HTTP errors!
try {
const response = await fetch('/api/users/999')
const data = await response.json()
} catch (error) {
// Only catches NETWORK errors, not 404s!
}
// ✓ CORRECT - Check response.ok
try {
const response = await fetch('/api/users/999')
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`)
}
const data = await response.json()
} catch (error) {
// Now catches both network AND HTTP errors
}
// ❌ BAD
const x = [1, 2, 3]
const y = x.map(z => z * 2)
// ✓ GOOD
const numbers = [1, 2, 3]
const doubled = numbers.map(num => num * 2)
// Level 1: Basic usage
fetch('/api/users')
// Level 2: With options
fetch('/api/users', {
method: 'POST',
body: JSON.stringify({ name: 'Alice' })
})
// Level 3: Full real-world pattern
async function createUser(userData) {
const response = await fetch('/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(userData)
})
if (!response.ok) {
throw new Error(`Failed to create user: ${response.status}`)
}
return response.json()
}
External resources (articles, videos) are valuable, but must meet quality standards.
Only include resources that are:
Each resource needs a specific, engaging 2-sentence description explaining what makes it unique. Generic descriptions waste the reader's time.
<!-- ❌ Generic (bad) -->
<Card title="JavaScript Promises Tutorial" icon="newspaper" href="...">
Learn about Promises in JavaScript.
</Card>
<!-- ❌ Generic (bad) -->
<Card title="Async/Await Explained" icon="newspaper" href="...">
A comprehensive guide to async/await.
</Card>
<!-- ✓ Specific (good) -->
<Card title="JavaScript Async/Await Tutorial" icon="newspaper" href="https://javascript.info/async-await">
The go-to reference for async/await fundamentals. Includes exercises at the end to test your understanding of rewriting promise chains.
</Card>
<!-- ✓ Specific (good) -->
<Card title="JavaScript Visualized: Promises & Async/Await" icon="newspaper" href="...">
Animated GIFs showing the call stack, microtask queue, and event loop in action. This is how async/await finally "clicked" for thousands of developers.
</Card>
<!-- ✓ Specific (good) -->
<Card title="How to Escape Async/Await Hell" icon="newspaper" href="...">
The pizza-and-drinks ordering example makes parallel vs sequential execution crystal clear. Essential reading once you know the basics.
</Card>
Description Formula:
Avoid in descriptions:
Articles (Prioritize):
| Source | Why |
|---|---|
| javascript.info | Comprehensive, well-maintained, exercises included |
| MDN Web Docs | Official reference, always accurate |
| freeCodeCamp | Beginner-friendly, practical tutorials |
| dev.to (Lydia Hallie, etc.) | Visual explanations, community favorites |
| CSS-Tricks | DOM, browser APIs, visual topics |
Videos (Prioritize):
| Creator | Style |
|---|---|
| Web Dev Simplified | Clear, beginner-friendly, concise |
| Fireship | Fast-paced, modern, entertaining |
| Traversy Media | Comprehensive crash courses |
| Fun Fun Function | Deep-dives with personality |
| Wes Bos | Practical, real-world focused |
Avoid:
Before including any resource:
Use ASCII art to visualize concepts. Make them boxed and labeled:
┌─────────────────────────────────────────────────────────────────────────┐
│ THE REQUEST-RESPONSE CYCLE │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ YOU (Browser) KITCHEN (Server) │
│ ┌──────────┐ ┌──────────────┐ │
│ │ │ ──── "I'd like pasta" ────► │ │ │
│ │ :) │ (REQUEST) │ [chef] │ │
│ │ │ │ │ │
│ │ │ ◄──── Here you go! ──────── │ │ │
│ │ │ (RESPONSE) │ │ │
│ └──────────┘ └──────────────┘ │
│ │
│ The waiter (HTTP) is the protocol that makes this exchange work! │
│ │
└─────────────────────────────────────────────────────────────────────────┘
| Component | When to Use |
|---|---|
<Info> | "What you'll learn" boxes, Key Takeaways |
<Warning> | Common mistakes, gotchas, prerequisites |
<Tip> | Pro tips, rules of thumb, best practices |
<Note> | Additional context, side notes |
<AccordionGroup> | Expandable content, Q&A sections, optional deep-dives |
<Tabs> | Comparing different approaches side-by-side |
| Content Type | Icon |
|---|---|
| MDN/Official Docs | book |
| Articles/Blog Posts | newspaper |
| Videos | video |
| Courses | graduation-cap |
| Related Concepts | Context-appropriate (handshake, hourglass, arrows-spin, , etc.) |
Before finalizing a concept page, verify ALL of these:
--- horizontal rules/concepts/slug)// "result")When adding code examples, create corresponding tests in /tests/:
// tests/{category}/{concept-name}/{concept-name}.test.js
import { describe, it, expect } from 'vitest'
describe('Concept Name', () => {
describe('Basic Examples', () => {
it('should demonstrate the core concept', () => {
// Convert console.log examples to expect assertions
expect(typeof "hello").toBe("string")
})
})
describe('Common Mistakes', () => {
it('should show the wrong behavior', () => {
// Test the "wrong" example to prove it's actually wrong
})
it('should show the correct behavior', () => {
// Test the "correct" example
})
})
})
Verify these elements before publishing any concept page:
<Steps> componentWeekly Installs
224
Repository
GitHub Stars
66.3K
First Seen
Jan 20, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
claude-code128
gemini-cli125
github-copilot125
opencode125
codex114
cursor106
API文档生成与管理指南:OpenAPI规范、Swagger使用教程与团队协作
11,700 周安装
| "As mentioned earlier" | Remove or link to the section |
"Promises: Handling Async Operations in JavaScript" |
"Promises: Handling Async Operations" |
"Call Stack" | "Call Stack: How Function Execution Works in JavaScript" | "Call Stack: How Function Execution Works" |
"Event Loop" | "Event Loop: How Async Code Actually Runs in JavaScript" | "Event Loop: How Async Code Actually Runs" |
"Scope" | "Scope and Closures: Variable Visibility in JavaScript" | "Scope and Closures: Variable Visibility" |
"this" | "this: How Context Binding Works in JavaScript" | "this: How Context Binding Works" |
"Prototype" | "Prototype Chain: Understanding Inheritance in JavaScript" | "Prototype Chain: Understanding Inheritance" |
"Understand JavaScript Promises for handling asynchronous operations. Learn to create, chain, and combine Promises, handle errors properly, and write cleaner async code." |
| Event Loop | "How async works" | "Discover how the JavaScript event loop manages async code execution. Understand the call stack, task queue, microtasks, and why JavaScript is single-threaded but non-blocking." |
| Call Stack | "Function execution" | "Learn how the JavaScript call stack tracks function execution. Understand stack frames, execution context, stack overflow errors, and how recursion affects the stack." |
| this | "Understanding this" | "Learn the 'this' keyword in JavaScript and how context binding works. Covers the four binding rules, arrow function behavior, and how to use call, apply, and bind." |
| DOM and Layout Trees | dom-and-layout-trees | dom or dom-layout-trees |
<Steps> | Sequential processes, numbered workflows |
<CardGroup> | Resource links (articles, videos, references) |
<Card> | Individual resource with icon and link |
sitemap