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

VMware installation of Centos8 system tutorial diagram (Chinese graphical mode)

Table of contents 1. Software and system image 2....

Summary of Vue watch monitoring methods

Table of contents 1. The role of watch in vue is ...

Docker installation of MySQL (8 and 5.7)

This article will introduce how to use Docker to ...

Summary of experience in using div box model

Calculation of the box model <br />Margin + ...

Example of writing mobile H5 to invoke APP (IOS, Android)

iOS 1. URL scheme This solution is basically for ...

Sample code for changing the color of a png image through a CSS3 filter

This method uses the drop-shadow filter in CSS3 t...

vue3 custom directive details

Table of contents 1. Registering custom instructi...

UCenter Home site adds statistics code

UCenter Home is an SNS website building system rel...

MySQL 8.0.18 stable version released! Hash Join is here as expected

MySQL 8.0.18 stable version (GA) was officially r...

Sample code for installing Jenkins using Docker

Two problems that are easy to encounter when inst...

Vue implements horizontal scrolling of marquee style text

This article shares the specific code for Vue to ...

Steps for Vue to use Ref to get components across levels

Vue uses Ref to get component instances across le...