EMCA-262 describes the basic concept of JavaScript implementation by "pseudo-language" called ECMAScript.
JavaScript draws on the syntax of C, is case-sensitive, the identifier begins with a letter, an underscore, or a dollar sign ($) , and the comment can be used // or/ * * /
Data type:
Six types of data
1, Undefined
2, Null
3, Boolean
4. Number
5, String
6, Object (a set of unordered name value pairs)
Operator: typeof Note is not a function that can be used for variables or numeric literals.
Undefined:
The undefined type has only one value, that is, a special undefined,
When the variable definition is uninitialized, its value is undefined.
var test; typeof test = = "undefined" //true
Undefined is also returned when performing a typeof operation on an undeclared variable
Null:
The value of the null type is NULL, which represents an empty object pointer,
The undefined value is derived from a null value.
typeof null = = ' object ';
If a defined variable is intended to be used to hold an object in the future, it is better to initialize the variable to null instead of the other value.
This allows you to know whether a variable has saved a reference to an object as long as it detects whether it is a null value.
Boolean:
The Boolean type, with a value of true and false, is case-sensitive.
Any one of the data types to be converted to Boolean simply calls the Transform function Boolean ()
var msg = "Hello"; var msgtobool = Boolean (msg); True
Data type |
Convert to True |
Convert to False |
Boolean |
True |
False |
String |
Non-empty string |
"" Empty string |
Number |
Not 0 digits |
0 and Nan |
Object |
Any object |
Null |
Undefined |
Not applicable |
Undefined |
The control leave statement (if) automatically performs the associated Boolean conversion.
Number:
Use IEEE754 to represent integers and floating-point values,
var intnum =/ / integer var octnum = 020 // octal is not valid in strict mode, throws an error var hexnum = 0xa // hexadecimal arithmetic operations are converted to decimal values.
Numerical range number,min_value; Number.MAX_VALUE; Returns inifinity, cannot participate in the operation.
NaN
A non-numeric value (not a number) is a special value that is used in cases where an operand that would have returned a numeric value did not return a numeric value. For example, any value in ECMAScript will return nan in addition to 0.
function isNaN () to determine whether the parameter is "not a numeric value";
IsNaN (NaN) //true IsNaN (//false converted to 10
IsNaN ("Blue")//true
numeric conversions
varnum = Parentint ("1234blue");//1234varnum = Parentint ("")//NaNvarnum = Parentint ("0xa")//Tenvarnum = Parentinr (22.5)// Avarnum = Parentint ("070")// Aboutvarnum = Parentint ("70")// -parsing octal ECMAScript3There's a disagreement with ECMAScript 5 .varnum = Parentint ("070")//3 ECMAScriptvarnum = Parentint ("070")//5 ECMAScriptThe second parameter specifies a cardinalityvarnum = Parentint ("AF", 16)//175varnum = Parentint ("AF");//NaN
Parentfloat () converts only 10 binary.