Skip to content

数据类型

一句话解释

数据类型 tells computer 什么 kind 的值 变量持有 — 文本, 数字, 真/假, and 所以 on.

用大白话说

A data type is a category that describes what a value is and what you can do with it. Common types include strings (text), numbers (integers and decimals), booleans (true/false), and more complex types like arrays and objects.

Types matter because the computer treats each kind of value differently. You can add two numbers together (5 + 3 = 8), but adding two strings concatenates them ("5" + "3" = "53"). Knowing the type tells the computer which operations are valid.

Some languages (like Python, JavaScript) figure out the type automatically from the value you assign. Other languages (like Java, C) require you to declare the type explicitly. Either way, understanding data types is essential to writing correct programs.

示例

javascript
let name = "Ada";      // string
let age = 25;          // number
let isReady = true;    // boolean

console.log(typeof name);     // "string"
console.log(typeof age);      // "number"
console.log(typeof isReady);  // "boolean"

typeof reveals 数据 类型 的 每个 变量: 字符串, 数字, and 布尔值.

常见混淆

  • 容易混淆的对象: 字符串 对比 integer

    关键区别: 字符串 是 文本 enclosed in quotes ("25"); integer 是整个数字 (25). "25" + "25" gives "2525", 但 25 + 25 gives 50.

相关术语

相关资源

相关课程

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表