logo

JavaScript 变量与数据类型

✏️ Editable
Loading...
Live Preview
+Enter Run+R Reset

About This Exercise

如果你是第一次写 JavaScript,这一关就是“起点课”。

变量可以理解成“贴了名字的盒子”,你把数据放进去,后面就能反复使用。

本关只做三件事:声明变量、给变量赋值、把变量打印出来。

你将学到:

  • letconst 的基本用法
  • 字符串(text)、数字(number)、布尔值(true/false)
  • console.log() 检查你写的代码是否正确
  • 为什么初学阶段要先把“变量”练熟
Beginner⏱ 15-20 min

Learning Objectives

  • 理解变量的概念和用途
  • 掌握 let 和 const 的区别
  • 认识 JavaScript 的基本数据类型
  • 学会使用 console.log 调试

Scenario

你正在写人生第一段 JavaScript。 目标不是“炫技”,而是能稳定完成:定义变量 -> 赋值 -> 打印结果。 只要把这条链路跑通,后面的函数、条件、循环都会更容易懂。

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

JavaScriptVariablesData TypesBasics