JavaScript 运算符
✏️ Editable
Loading...
Live Preview
⌘+Enter Run⌘+R Reset
About This Exercise
运算符可以理解为“数据之间怎么计算、怎么比较”的规则。
这一关按“算术 -> 比较 -> 逻辑”顺序走,先会算,再会判断。
你将学到:
- 算术运算符:
+、-、*、/、% - 比较运算符:
===、!==、>、< - 逻辑运算符:
&&、||、! - 空值合并:
??
Beginner⏱ 15-20 min
Learning Objectives
- 掌握基本算术运算
- 理解比较运算符的区别
- 学会使用逻辑运算符
- 了解空值合并运算符
Scenario
你在做一个小工具:先算价格,再判断是否相等,最后判断一个人是否满足条件。
这是新手最常见的真实编程流程。
Why Do This
- Frontend JS is not just about knowing the syntax — the key is reliably manipulating the DOM and managing interaction state.
- Break down the event flow (trigger -> handle -> update UI) before coding, and you will make significantly fewer errors.
- Rule-based validation helps you develop a testable frontend mindset.
Hands-on Practice
- Write out the event flow in comments first, then implement the functions.
- Add an edge case branch for invalid input or empty data.
- Explain why each validation rule is needed.
Common Mistakes
- Only testing the happy path without verifying edge inputs or repeated clicks.
- Mixing event binding and state updates together, making future maintenance difficult.
- Console output looks correct but the UI is not actually updated.
Deliverable
A reusable interaction component scaffold (event flow description + key functions + edge case handling).
My Progress
Completed Steps0 / 3
Total Attempts0
Best Score0%
Completion Criteria (Checkable)
Confirm before completing this Lab
Reflection Questions (Recommended)
Describe the event flow of this Lab in 2-3 sentences (trigger -> handle -> update).
What edge case did you add? Why is it easy to miss?
How confident are you with this interaction pattern now?
Tags
JavaScriptOperatorsArithmeticLogic