ECMAScript: is a set of standard, core, definition specification, syntax, data type, basic object, keyword ...
HTML tag type: block, inline, inline-block, table ... Type allows us to distinguish between different types of tags knowing what style to define it. For example, the block type can be set to a wide height.
Data types in javascript:
/*
Classify data types according to typeof:
Number (NaN), String, function, Boolean, object (obj, element in document, [], {}, NULL), undefined (1 really does not define 2 Although the definition does not give a value)
The standard advocates two types of data:
Base type: number, String, function, Boolean, null, undefined
Type: Object
*/
1 vari = 100;2Alerttypeofi);// Number3 4 vars = ' abc ';5Alerttypeofs);//string6 7 varb =true;8Alerttypeofb);//Boolean9 //If (12<90) If the value in parentheses is automatically converted to Boolean type boolean value only Ture, FalseTen One functionFN1 () {alert (1);} AAlerttypeofFN1);//function - - varobj =window; the varobj =document; -AlerttypeofOBJ);//Object - - vararr = [1,2,3,4]; +AlerttypeofARR);//Object - + varJSON = { A' Name ': ' Xiaowang ', at' Age ': 5 - }; -AlerttypeofJSON);//Object - - varn =NULL; -Alerttypeofn);//Object in - varu; toAlerttypeofu);//undefined
In addition to object types other than empty objects, you can add custom properties.
Data type conversions:
HTML tag types can also be converted, such as inline conversion to block.
var a = ' 100 ';
alert (a+100); 100100 String Connection
The string is converted into a numeric type:
coercion type conversion/display type conversion Number (); parseint (); Parsefloat ();
1) Method:
Number ();
var a = ' 100 '; ' 000100 ', ' +100 '
Alert (number (a)); 100
var a = ';
Alert (number (a)); 0
var a = true;
Alert (number (a)); True 1 False 0
var a =function () {alert (1);}; Alert (number (a)); NaN can't go.
var a = []; 0
var a = ["]; 0
var a = [123]; 123
var a = [' 123 '];//123
var a = [n/a]; NaN
var json = {}//nan not go
var a = null//0
var A; Alert (number (a););//nan
Summary: JSON, undefined, function, and multi-object arrays are all Nan and cannot be transferred.
parseint (a,10); Parsefloat (a,10); By default there are two parameters, and the rear represents 10 binary
var a = ' 100px ';
The number () method is Nan, because the method is to convert the whole ;
parseint (a)//100 This method is one by one, if the discovery is no longer a number is truncated. This method can only turn 200px to extract the numbers, and the other true functions are Nan. It's usually used to turn the string that is the number in front
' +200 ' Both of these methods can be turned, +-space, etc. are recognized. It will continue to run back to see if there are any numbers extracted.
var a = ' 123,400 yuan '; parseint//don't know the decimal point parsefloat//only know the first decimal point 12.34
implicitly-typed conversions :
+ 200+ ' 3 '//2003 turns into a string
-*/% ' 200 '-3//197 turn into digital
+ +--var a = ' ten '; A++;alert (a); 11 turn into a number
>< alert (' >9 '); True turns into a number
Take the counter alert (! ' OK ');//false no matter! What's on the right is going to turn into a Boolean value
= = Alert (' 2 ' ==2); True no matter what the data type is
Alert (' Ten ' > ' 9 '); False the comparison of the string and the comparison of the number is different, will be a one of the comparison 1:9 corresponding code value is small, so false. No longer compare to the future
= = = Alert (' 2 ' ===2); Two different data types with congruent, first judge the type and then judge the value, more rigorous than = =, But there is no data type conversion
Nan Applications:
1,var a = number (' abc '); alert (a);//nan alert (typeof a); number so the numbers and number types are different. Nan is a numeric type but not a number
2, once the program appears Nan, indicating that the illegal operation must be done
3,nan is Fasle if (NaN)
4, numbers and strings compared to themselves are true,nan compared to their own is false
NaN is not a numeric type of number
IsNaN () is not a number (not a number)
IsNaN (); True false//To determine if certain values are numbers; Don't like numbers, hate numbers;
Alert (IsNaN (' 250 ')); False the internal first will be given to number () conversion and then judge the
Alert (IsNaN (true)); False number converted to 1
It doesn't hate number types (such as Nan) hate numbers
Alert (IsNaN (NaN)); True
operator :
1) Arithmetic:
+ Converts a number to a string in a type conversion
-*/% can convert a string to a number in a type conversion, if the conversion is not a Nan
2) Assignment: =, + =,-=, *=,/=,%=
3) Relationship:<, >, <=, >=, = =,! = (unequal), = = =,!== (all ranges)
4) Logic:&& and, | | OR,! No
var a = 20<90&&20;alert (a); Pop-up 20, left set will go to the right
var a = 120<90&&20;alert (a); Eject false
var a = 120<90| | 20;alert (a); Eject 20, even if the left is false, will also go to the right
Program Flow control :
1) Judgment:
if () {}else if () {}else{} This form can also be written with switch
The If () {}else{} form can be written using the three-mesh (ternary) operator
2) Loop: while, for
3) Jump out: Break jump out of the loop, continue skip this cycle
To pass the parameter:
When you do something, if you find that two or more places on the page are almost the same, you can use the function to pass the parameter, this time should have a sense of communication, such as large portals on the home page many tabs, the same page has several sets of picture switch. To implement code reuse, take something different and pass it through the parameters. (such as ID, event, etc. can be used as parameters). When writing, try to ensure the following points:
1) Try to ensure that the same HTML code can be selected by the parent sub-elements;
2) The core of the main program to implement first, and then use a function package up;
3) to find out the different values of each group, through the transfer of parameters to achieve.
Summary of the last true and false questions:
True: True, numbers that are not 0, non-empty (spaces are also non-empty) strings, non-empty objects (functions, elements that can be found, [], {})
False: False, 0, empty string ("'), null null object, undefined (element not found)
JavaScript language Core