1. Data Type1.1 Why do we need data types?In a computer, different data occupies different amounts of storage space. In order to divide data into data of different required memory sizes and make full use of the storage space, different data types are defined. 1.2 Data Types of VariablesJavaScript is a weakly typed or dynamic language, which means that there is no need to declare the data type of a variable in advance. The type will be automatically determined while the program is running. (The variable type of js is determined only when the program is running, based on the data type of the value on the right side of the equal sign) var age = 10; //This is a numeric data type var myName = 'lili'; //This is a string data type 1.3 Data Type ClassificationJS divides data types into two categories: Simple data types (Number, String, Boolean, Undefined, Null) Complex data types (object) 2. Simple data types (basic data types)The simple data types in JavaScript and their descriptions are as follows:
2.1 Number1. Digital systemCommon bases: binary, octal, decimal, hexadecimal Octal number sequence range: 0~7 starting with 0 Hexadecimal number sequence range: 0~9 and A~F starting with 0x 2. Digital rangeMaximum and minimum values of numbers in JavaScript alert(Number.MAX_VALUE); //1.7976931348623157e+308 alert(Number.MIN_VALUE); //5e-324
2.2 String1. String escape characterThe escape characters all start with \. Commonly used escape characters and their descriptions are as follows: Escape character explanation\n The meaning of newline
2. String lengthThe length of the entire string can be obtained through the length property of the string var myname = 'my name is andy'; console.log(myname.length); 2.3 BooleanBoolean values have two values: true and false, where true means true and false means false. When adding a Boolean value to a number, true is 1 and false is 0. console.log(true + 1); //2 console.log(false + 1); //1 3. Data type conversion3.1 Convert to string
3.2 Convert to digital type
number() // Convert to a number number('10') // 10 number('abc') // NaN number(true) // 1 number(false) // 0 number(null) // 0 number(undefined) // NaN parseInt() // Convert to a number and round down // Get integers from the converted data from the front to the back. Once one is found, it will not search again. Only the code that starts with an integer will be found: parseInt('12.345') // 12 parseInt('12abc') // 12 parseInt('abc12') // NaN parseInt(true) // NaN parseInt(false) // NaN parseInt(undefined) // NaN parseInt(null) // NaN Note: These characters must contain numbers and start with numbers, otherwise they are all NaN parseFloat() // Convert to number, integer, decimal code: parseFloat('12.345') // 12.345 parseFloat('12.345abc') // 12.345 parseFloat('abc12.345') // NaN parseFloate(true) // NaN parseFloat(false) // NaN parseFloat(undefined) // NaN parseFloat(null) // NaN Note: These characters must contain numbers and start with numbers, otherwise they are all NaN Implicit Conversion1. When one of the left and right sides of + is a string, the other one will be quietly converted into a string for concatenation 2. Mathematical operators convert both sides into numbers for arithmetic operations - When one of the left and right sides is a string, the + sign will concatenate them. When there is no string on either side, the + sign can also convert both sides into numbers. 3. When one of the comparison operator is a number, the other one will be quietly converted to a number for comparison. 3.3 Convert to BooleanValues that represent empty or negative values will be converted to false, such as '', 0, NaN, null, and undefined. Other values will be converted to true. String to Boolean type, empty string is false, and all others are true. SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: MySQL msi version download and installation detailed graphic tutorial for beginners
>>: CSS3 achieves cool 3D rotation perspective effect
Git is integrated in vscode, and many operations ...
Table of contents Preface NULL in MySQL 2 NULL oc...
Table of contents 1. Control the display and hidi...
Table of contents background Understanding compos...
This article example shares the specific code of ...
Preface To help ensure that your web pages have a ...
Table of contents Preface 1. How to write functio...
In order to make the page display consistent betwe...
Preface DISTINCT is actually very similar to the ...
Preface What is the role of an agent? - Multiple ...
Install 8.0.13 based on MySQL 6.1.3. MySQL 8.0.13...
Table of contents Shallow copy Deep Copy Replenis...
Installation Environment 1. gcc installation To i...
effect: The GROUP_CONCAT function can concatenate...
This article takes the connection error ECONNREFU...