Detailed explanation of the seven data types in JavaScript

Detailed explanation of the seven data types in JavaScript

Preface:

All major languages ​​have basic types, such as Python, Java, and C series. The existence of basic types is indispensable, just like integers in arithmetic and Chinese characters in Chinese characters. It is used to represent these. It is quite important to think about it. Then js has five common basic data types: String, Number, Boolean, Undefined, Null, and two common complex types Object and Symbol.

Detailed introduction:

Serial number type Nick name scope Common methods introduce
1 String String
.toString() Converts an object to a String type
.length property, used to get the length of the String type character
String type, mainly used to represent English, Chinese and other string types wrapped by single quotes '' or double quotes ""
2 Number Numeric Types -1.7976931348623157E+308 ~ 1.7976931348623157E+308 isNaN(number) Determines whether it is a number type Numeric types, whether decimals or integers, negative numbers, etc., are represented by the number type
3 Boolean Boolean There are only two values, true and false, true means true and false means false
4 Undefined Undefined Indicates that the type is declared but the value is undefined
5 Null null Indicates that the object reference is null
6 Object Object Object is a key-value type value enclosed in curly brackets.
7 Symbol Unique Values Used to represent unique values, different values

practise:

    //String
	let str = "hello js";
    console.log(str.toString); //Print: hello js
    console.log(str.length); //Print: 8
    console.log(str.substr(1,3));//Method: Split and print the string:ell
    console.log(str.split(' ')); //Method: print by grouping according to specified parameters ['hello' 'js']
    //Number
    let num = 123;
    console.log(!isNaN(num)); //Judge whether it is NaN, if not, it means it is a value //Boolean
    let flag = false;
    if(flag) { //The print result is false console.log("The result is true");
    }else{
        console.log("The result is false");
    }
    //Undefined
    let d;
    let val = `When an object is unassigned, its current value is: ${d}`;
    console.log(val); //Print: When an object is unassigned, the current value is: undefined
    //Null
    let a = null
    let nul = a;
    console.log(nul); //Print: null
    //Object
    let obj1 = {
        "name":"Zhang San",
        "age":24
    }
    //Symbol
    let sy = Symbol("1");
    if(sy == Symbol("1")) { //Print: the result is false console.log("the result is true");
    }else{
        console.log("The result is false");
    }

Summarize

This article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM!

You may also be interested in:
  • JavaScript data type conversion
  • Introduction to JavaScript basic syntax and data types
  • Eight essential data types for getting started with JS
  • Let's take a look at the most detailed explanation of JavaScript data types
  • Detailed explanation of basic data types in js
  • Eight JavaScript data types
  • Detailed explanation of data types in JavaScript basics
  • Detailed explanation of JavaScript data types
  • Introduction to Data Types in JavaScript

<<:  Introduction to SSL certificate installation and deployment steps under Nginx

>>:  An article to help you learn CSS3 picture borders

Recommend

Detailed explanation of how to adjust Linux command history

The bash history command in Linux system helps to...

Text pop-up effects implemented with CSS3

Achieve resultsImplementation Code html <div&g...

How to configure multiple projects with the same domain name in Nginx

There are two ways to configure multiple projects...

About VSCode formatting JS automatically adding or removing semicolons

introduction It is okay to add or not add a semic...

Example of how to adapt the Vue project to the large screen

A brief analysis of rem First of all, rem is a CS...

Detailed explanation of the loading rules of the require method in node.js

Loading rules of require method Prioritize loadin...

Detailed tutorial on downloading mysql on Windows 10

MySQL versions are divided into Enterprise Editio...

MySQL slow query: Enable slow query

1. What is the use of slow query? It can record a...

Binary Type Operations in MySQL

This article mainly introduces the binary type op...

How to install Mysql5.7 in Centos6

environment Centos 6.6 MySQL 5.7 Install If the s...

Example explanation of alarm function in Linux

Introduction to Linux alarm function Above code: ...

Front-end advanced teaching you to use javascript storage function

Table of contents Preface Background Implementati...

How to reset the initial value of the auto-increment column in the MySQL table

How to reset the initial value of the auto-increm...