Home > Web Front-end > JS Tutorial > Common data types in js

Common data types in js

下次还敢
Release: 2024-05-01 05:27:16
Original
345 people have browsed it

Common data types in JavaScript are divided into basic types (Number, String, Boolean, Null, Undefined) and complex types (Array, Object, Date, RegExp, Error). Use the typeof operator to determine the type of data, such as console.log(typeof 42) output "number".

Common data types in js

Common data types in JavaScript

Data types in JavaScript refer to the storage and processing of different types Classification of variables in the data. The following are several common data types in JavaScript:

1. Basic data types

  • Number: Numeric value.
  • String: String.
  • Boolean: Boolean value (true or false).
  • Null: Null value.
  • Undefined: The value of the variable is not declared.

2. Complex data type

  • Array: A set of elements arranged in sequence.
  • Object: A set of key-value pairs.
  • Date: Date and time.
  • RegExp: Regular expression.
  • Error: Error object.

3. Special data types

  • Symbol: Unique identifier.
  • BigInt: An integer, but larger than Number.

How to determine the type of data

You can use the typeof operator to determine the data type of a variable. For example:

<code class="js">console.log(typeof 42); // "number"
console.log(typeof "hello world"); // "string"
console.log(typeof true); // "boolean"
console.log(typeof null); // "object"
console.log(typeof undefined); // "undefined"</code>
Copy after login

It should be noted that although null is a special value, it is treated as an object in JavaScript.

The above is the detailed content of Common data types in js. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template