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

mysql5.7.19 winx64 decompressed version installation and configuration tutorial

Recorded the installation tutorial of mysql 5.7.1...

How to solve "Unable to start mysql service error 1069"

Today, when I was on the road, a colleague sent m...

Implementation of formatting partitions and mounting in Centos7

Linux often encounters situations such as adding ...

Method for realizing Internet interconnection by VMware virtual machine bridging

After installing VMware and creating a new virtua...

Zookeeper stand-alone environment and cluster environment construction

1. Single machine environment construction# 1.1 D...

Use simple jQuery + CSS to create a custom a tag title tooltip

Introduction Use simple jQuery+CSS to create a cus...

Docker exposes port 2375, causing server attacks and solutions

I believe that students who have learned about th...

Complete list of CentOS7 firewall operation commands

Table of contents Install: 1. Basic use of firewa...

How to use HTML+CSS to create TG-vision homepage

This time we use HTML+CSS layout to make a prelim...

HTML tag marquee realizes various scrolling effects (without JS control)

The automatic scrolling effect of the page can be...

How to create a responsive column chart using CSS Grid layout

I have been playing around with charts for a whil...