Data types and method data types
- Number does not distinguish between integers and floating-point numbers
- String strings
- Boolean True/false Boolean
- Object NULL Array
- function functions
Undefined not defined
Number method
Method |
DES |
Number () |
constructor, parameters must be all numbers, otherwise Nan (not a number) is returned |
parseint () |
Converts a parameter to a number, and the integer part encounters a stop that is not a number |
Parsefloat () |
The argument is converted to a number, and a stop is encountered. |
ToFixed () |
Keep decimals (rounded), return string |
Note: The Nan data itself is not equal and the type is number
var str = "101.123px";var n = Number(str);alert(isNaN(N));//truealert( n == n );//false
Math Mathematical Functions
Method |
DES |
Math.pow () |
Seeking the second party |
Math.Round () |
Rounding to integers |
Math.ceil () |
Rounding up |
Math.floor () |
Rounding down |
Math.min () |
Take the minimum value |
Math.max () |
Take maximum value |
Math.random () *n |
Random number of 0-n to be taken |
var n = Math.random()*10 + 20//取10到30之间随机数parseInt(n)取整
String method
Method |
DES |
Str[index] |
Take a single character ———— compatible ie8+ |
Str.charat (Index) |
Take a single character ———— compatible with all * |
Number.tostring () |
Convert numbers to Strings |
Str.touppercase () |
Capitalize a string letter |
Str.tolowercase () |
Change the string letter to lowercase |
Str.indexof |
("Want to find text", the starting position of the query) |
Str.substring () |
Intercept the string (the parameter will be compared between, which parameter is placed in the front, the parameter is negative, becomes 0) |
Str.slice () |
Intercept string (parameter two cannot be less than parameter one) |
Str.split ("Want to use it as a segmented text") |
Returns an array |
Boolean Boolean value
Judging condition is true or False (true:1/flase:0)
Five false statements are as follows, and the rest are true, including empty objects, empty arrays
undefinednull0NaN""
Note: null and undefined
null转换为数字的时候 为0,在做条件判断为假 类似于正确空值的填补 undefined 转换为数字 为NaN,在做条件判断为假 类似于错误空值的填补null 关键字, 非对象undefined ==> undefined1+undefined ==> NaN1+null ==> 1
JS operator
DES |
| Sign
Operator |
+ - * / % |
Assignment operations |
= += -= /= %= |
Judging condition symbols |
> < = = <= >=! = is not equal to!== = = = = Constant Equals, also determines the data type |
logical operators |
With && or || not! |
Can be calculated when the calculation will be performed, can not be calculated will be a variety of problems (error NaN);
- Except for the plus sign-*/% forces parameters to be converted to numbers
- Addition operations as long as there is a string, the addition is a string concatenation
- && conditions to stop and return to Flase
- || Condition encountered true stop, return True
For loop
for(var i=0; i<10; i++){ if( i==5 ){ //continue;跳过本次循环,到循环尾 break;//中断循环 } console.log(i);}for(var key in document) { console.log(key +"======"+document[key]); // 查看document里面所有的方法 }
Process Control
if ( 10>1 ) { alert(1); }else if( 5<50 ){ alert(2); }else if( 10>20 ){ alert(3); } // 只有一条真语句 if( 8 > 0 ) alert(‘This is 8 > 0‘);
JS data Types and methods