Data type
1) Basic data type (value type/primitive value type)
+ number + string string + Boolean + null pointer undefined + Es6 new unique value type symbol + bigintCopy the code
2) Reference data types
+ function (primary type) + function (primary type)Copy the code
2. Common output modes in JS
Console controls output in browser console + console.log() console output log + console.dir() console detail output + console.table() Output data in table form in console + console.time() / console.end () counts the time consumed by a program + console.warn() prints warnings +...Copy the code
Windows prompt box
+ alert() box 1. Output specified information 2. Block main thread rendering 3. Default conversion toString (toString method) object toString "[object object]" + confirm() confirm cancel prompt + prompt() add a reason in addition to confirmCopy the code
Inserts content into the specified container
Write to the page + innertHTMl/interText specifies to the page the input content in the specified container (which also becomes a string) a. B. The innerHTML recognizes and renders the tag text, and the innerText treats everything as normal textCopy the code
Number data type
NaN not a number is not a valid number, but is of type number + infinity NaN of type number is not equal to any value (including itself)Copy the code
isNaN
Professional used to detect whether a value is a valid number (to test whether a value is not valid number, if a valid number, return false if it is not a valid number, return true) + when using isNaN for testing, if the test values are numeric type, you need to put it into a digital type, > parseInt([value]) > parseFloat([value]) > parseFloat([value])Copy the code
Number is a built-in JS conversion method that can “force” other data types to numeric types
+ converts a string to a number. If a string has a non-valid numeric character, the result is NaN. Null =>0 undefined=> NaN + Cannot convert symbol type to numbers, otherwise an error will be reported + convert object to number first convert object to string, Number (' [object object] ') =>NaN + array object + other object format =>NaNCopy the code
Console. log(100 + true + 21.2 + null + undefined + "Tencent" + [] + null + 9 + false); 101 + 21.2 => 122.2 122.2 + null => 122.2 122.2 + undefined => NaN NaN + "Tencent" => "NaNTencent" "NaNTencent" + [] => "NaNTencent" + null => "NaNTencentnull" "NaNTencentnull" + 9 => "NaNTencentnull9" + false => "NaNTencentnull9false" Note that when performing the four operations, the data type is not Number, the first conversion to the Number type should be performed. Once the string is encountered, the string concatenation is performed immediately. The basic value is directly concatenated, and the string concatenation is not performedCopy the code
ParseInt /parseFloat also converts other data types to number (specifically for converting strings to numbers)
Processing principle and the Number is not the same, they are the string is converted to a digital type (if the value is not a string processing, need to convert a string, and then to convert the Number type) = > starts at the far left string search, to find an effective digital character converted to digital, has met a non effective numeric characters, If the first character is not a numeric character or a minus sign, parseInt() returns NaN; That is, converting an empty string with parseInt() returns NaN.Copy the code
String data type
In JS single quotes double quotes and back quotes are all strings convert other data types to strings +String ([value]) +[value].toString () Ordinary objects to strings are "[objec Object]" Array objects converted to strings are "first item, second item, third item... (Each item in the array is separated by a comma)Copy the code
In JS commonly used mathematical operations
+ - * / + subtraction, multiplication, and division % (brane) + - * / + subtraction, multiplication, and division % (brane) + - * / + subtraction, multiplication, and division % If a string appears on either side of the plus sign, it becomes a string concatenation. If a string appears on either side of the plus sign, it becomes a string concatenationCopy the code
Boolean data type
Boolean ([value]) +! [value] Converts the specified value to a Boolean type. [value] return value to Boolean ** rule: 0 /NaN/null/undefined/empty string, the last is false, the rest is true** In conditional judgment, each condition must be true/falseCopy the code
*/ / if (1 == 1) {} // if (1) {// //=> Then check program of true and false / /} / / if (3 + '3 p') {} / / = > 3 + '3 p' = > '33 px' true / / if (3 - '3 p') {} / / = > 3 - '3 p' = > false NaNCopy the code
Object data type
All objects should have the following characteristics: 1. Use key: value pairs to describe the characteristics of an object (each object is a complex, there are zero to multiple groups of key: value,... } Each group of key-value pairs is in the format of key: value, separated by commas. 3. Key does not refer to a data type, and value can be any data type. 1. Add or modify attributes and attribute values the attribute name (key) of an object cannot be repeated. If there is no such attribute before, it is new. Attribute name = attribute value point + object = attribute value 2. Keys (obj) 3. If the specified property does not exist, the value of the property is undefined. XXX = null. 2) True delete: Completely remove the property from the object. Eg: Delete obj. XXX the property name of the object cannot be a reference data type valueCopy the code
Let n = 100 obj['n'] =200 obj[n] =200 => {100:200} => obj[100] =200 The latter is a string value) which represents the stored value 100 (a numeric format)Copy the code
If the operation is based on the object [attribute name], ensure that the attribute name is a value (string, number, Boolean, etc.). If it is not a value but a variable, the value stored in the variable is used as the attribute name of the object. => Based on the object. 1 => there is a limitation that the property name cannot be a number object. => {“[object Object]”:” Doraemon “} => If the attribute name must be an object, it can only be handled based on the new data structure Map in ES6
An array is a special object. 1. Its property name is a number. The number starts from zero and increases step by step. By default, a length attribute stores the length of the array
Let arr = [1,2,3] arr[0] = 1 arr.lenth = 3Copy the code