Good variable names are just good English sentences waiting to happen. In this lesson, you'll learn how TypeScript developers name things — and why the words they choose reveal their thinking.
好的变量名就是等待被说出口的英语。在这节课里,你将学会 TypeScript 开发者如何命名,以及他们选用的词汇如何体现其思维方式。
Read the Code
// 🚫 Bad naming — a computer could read this, but a human cannot
const x = 86400;
const arr = ['Alice', 'Bob', 'Charlie'];
// ✅ Good naming — English tells the story
const SECONDS_PER_DAY = 86400;
const activeUsers: string[] = ['Alice', 'Bob', 'Charlie'];
// 📖 Notice how the variable name answers a question:
// 'What do these users have in common?' → they are 'active'
// Using descriptive verbs for boolean variables:
const isLoggedIn: boolean = true; // is... → state question
const hasPermission: boolean = false; // has... → possession question
const shouldRedirect: boolean = true; // should... → intent question
💡 Tip: read each line aloud in English. The comments are your guide.
Vocabulary Focus
descriptive
/dɪˈskrɪptɪv/
adjective
描述性的,能清晰说明特征的
convention
/kənˈvɛnʃn/
noun
惯例,约定俗成的规范
intent
/ɪnˈtɛnt/
noun
意图,目的
boolean
/ˈbuːliən/
noun / adjective
布尔值(true/false)
Comprehension Check
Answer in your head first — then reveal to see the model answer.
Q1: Why is `SECONDS_PER_DAY` better than `x`?
Q2: What prefix pattern is used for boolean variables in the example?
Key Insight▼ Reveal