1. Basic types (6 types):
Number (String) String (String) Boolean (Boolean)
Undefined Null ES6-Symbol (Unique)
1.1 Number
the let NUMBER_1 = 15; // decimal notation the let NUMBER_2 = 017; // octal notation the let NUMBER_3 = 0xF; // hexadecimal notation // However, the output of the above procedures will be converted to decimal notation output console .log (number_1, number_2, number_3)
1.1.1 Decimal (float)
Numbers with a decimal point use values of type float.
let height = 1.75;
1.1.2 Special values
NaN (not a number) calculation error, type conversion failed
Infinity (divisor is zero)
1.2 String
Use double quotation marks ("") or single quotation marks ('') to represent data of type string
let name = "Someone";
1.3 Boolean type (boolean)
There are only two values of type boolena: true or false, representing true and false
1.4 undefined
The data type undefined has only one value undefined.
The difference between undefined and undeclared variables
Undefined variable: a variable has been declared but not assigned, the default value is undefined;
var address; console.log(address);//undefined
Undeclared variable: use it without declaring the variable-the console will report an error
console.log (add); // error -add not defined, add this variable is not declared;
1.5 empty
The data type null has only one value null. You can clear the contents of a variable by assigning a null value to the variable
1.6 ES6 - Symbol
Did not learn here (omitted)
2. View the data type of the basic type value
Syntax: typeof variable name / value or typeof (variable name / value)
console.log( typeof 12 ) //number console.log( typeof '曹操' ) //string console.log( typeof true ) //boolean console.log( typeof undefined) //undefined console.log( typeof null ) //object 这是个bug console.log( typeof Symbol() ) //symbol
Why typeof null gets object instead of null --- It doesn't know too much about the underlying layer. I only know that it is a bug and because null starts with 000 in JavaScript binary, and if the first three bits of binary in JavaScript are all 0, it will be judged as object type