You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaScript中的值类型包含哪些数据类型?并确认number、boolean、string、null、undefined、bigint、symbol是否为值类型

JavaScript值类型(原始类型)详解

Great question! Let's break this down clearly for you. First off, you're right that objects, functions, and arrays fall into JavaScript's reference types category. Now let's dive into the primitive (value) types you're asking about.

What counts as a value type in JavaScript?

In ECMAScript standards, primitive types (the official term for what you're calling "value types") are the most basic data types that store actual values directly, rather than pointing to a memory reference like objects do.

There are exactly 7 primitive types defined in modern JavaScript, and they're exactly the ones you listed:

  • number: Covers integers, floating-point numbers, plus special values like NaN and Infinity
  • boolean: Only has two possible values: true and false
  • string: Even though strings have object-like methods (like .toUpperCase()), they're still primitive values at their core
  • null: A special primitive representing an intentional empty value (fun fact: typeof null returns "object"—that's a long-standing JS bug, but it's still officially a primitive type)
  • undefined: Represents an uninitialized value; variables declared without assignment default to this
  • bigint: Used for integers larger than the maximum safe value of number (written with an n suffix, e.g., 9007199254740991n)
  • symbol: Unique, immutable values often used as unique keys for object properties

Confirming your list

To directly answer your question: all the types you mentioned—number, boolean, string, null, undefined, bigint, symbol—are absolutely value types (primitive types).

A quick way to tell them apart from reference types: when you assign a primitive value to another variable or pass it as a function argument, you're copying the actual value. With reference types, you're copying a pointer to the same object in memory. Here's a quick example to illustrate:

// Value type behavior
let num1 = 25;
let num2 = num1;
num2 = 50;
console.log(num1); // Logs 25—num2 was a copy, so changing it doesn't affect num1

// Reference type behavior
let user1 = { name: "Steven" };
let user2 = user1;
user2.name = "Steve";
console.log(user1.name); // Logs "Steve"—both variables point to the same object

内容的提问来源于stack exchange,提问作者Steven

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 19:23:11