乐闻世界logo
搜索文章和话题

How Many Value Types Exist in JavaScript?

2024年6月24日 16:43

JavaScript has 8 primitive value types:

  1. Undefined:A variable with no assigned value has the type undefined. For example: let x;
  2. Null:The type representing the absence of a value. For example: let x = null;
  3. Boolean:The boolean type has two values: true and false. For example: let x = true;
  4. String:The type used for textual data. For example: let x = 'hello world';
  5. Number:The type used for representing integers and floating-point numbers. For example: let x = 3.14;
  6. BigInt:A type used for storing and manipulating integers of arbitrary size. For example: let x = 9007199254740991n;
  7. Symbol:A unique and immutable data type. For example: let x = Symbol('hi');
  8. Object:The object data type is used for storing complex data structures. For example: let x = {firstName:"John", lastName:"Doe"};

These 8 types can be broadly categorized into two types:

  • Primitive values (Undefined, Null, Boolean, Number, String, Symbol, BigInt)
  • Object values (Object)
标签:JavaScript前端