1. Character conversion
var S1 = "a";
var s2 = "1.1";
var s3 = "Z";//letter ' Z ' cannot be converted to a number, so or return nan
var b = false;
var f = 1.1;
var o = {
valueof:function () {
return-1;
}
};
S1 =-s1; Value becomes numeric-1
s2 =-s2;//value becomes numeric-1.1-s3 =-s3;//value becomes
NaN
b =-b;
//value becomes numeric 0
f = f; Change to-1.1
o =-O; 1 The valueof () method that first executes the object returns-1,--1 is 1
o = +o;//-1 o valueof () value is -1,+-1 or-1
2. Special character operation
var result1 = 5-true; 4 because true is converted to 1
var result2 = NaN-1; Nan Nan is not a number, and any number to do any arithmetic is Nan
var result3 = 5-3; 2
var result4 = 5-""; 5 because "" is converted to 0
var result5 = 5-"2"; 3 because "2" is converted to 2
var result6 = 5-null;//5 because null are converted to 0
3. Variable string operation
var value1 = ten;
var value2 = true;
var value3 = null;
var value4;//value4 is not assigned a value is underfined converted to a string is ' underfined '
alert (String (value1)); "Ten"
Alert (String (value2)); "True"
alert (String (VALUE3)); "Null"
alert (String (VALUE4)); "Undefined"
4, the number of the conversion
var num = ten;
Alert (num.tostring ()); "10" Default decimal
Alert (num.tostring (2)); "1010" Binary
Alert (num.tostring (8)); "12" Octal
alert (num.tostring); "10" decimal
alert (num.tostring); "A" hex
5. String comparison operation
var result1 = 5 > 3; True
var result2 = 5 < 3;//false
var result3 = "Brick" < "alphabet"; compare lowercase letters in alphabetical order after uppercase letters C3/>var RESULT4 = "Brick" toLowerCase () < "Alphabet". toLowerCase (); False alphabetical order comparison
var result5 = "< 3";//true character 2 less than character 3
var result6 = "%" < 3;//false at this time ' 23 ' converted to 23
VA R result7 = "a" < 3; False because "a" becomes Nan character ' a ' cannot be converted to numeric
var result8 = nan < 3;//false Nan and any number comparisons cannot be converted to numbers, so it is always false
var Result9 = NaN >= 3; False
6. Conversion of character into system
var num1 = parseint ("AF"); 175 output Decimal data in accordance with 16 10*16+15*1
var num2 = parseint ("AF"); Nan does not specify a system, and the default is 10-in-conversion, because AF is not in the decimal range, return nan
alert (NUM1);
alert (num2);
7, the use of parseint
var num1 = parseint ("1234blue"); 1234
var num2 = parseint (""); NaN character ' cannot be converted to digital
var num3 = parseint (' 0xA '); 10-hexadecimal 16-in-
var num4 = parseint (22.5);
var num5 = parseint ("a"); 70-decimal
var num6 = parseint ("0xf"); 15 16 to 15
8, the use of the number object
var num1 = number ("Hello world!"); NaN
var num2 = number (""); 0 empty string can be converted to 0 this parseint () is not the same as
var num3 = number ("000011"); One
var num4 = number (true); 1
9. Nan Usage
Alert (nan = = nan); False
alert (isNaN (NaN)); True
alert (isNaN); False is a number
alert (isNaN ("ten")); can be converted to number
alert (isNaN ("Blue"))//true? Cannot is converted to a number
alert isNaN (t Rue)); False? can converted to number 1
10, the system maximum number
var result = Number.MAX_VALUE + 1;
Alert (isfinite (result)); False
11, Infinity Infinity
Alert (5 * 6);
Alert (5 * NaN); NaN
alert (Infinity * 0);//nan
alert (Infinity * 2);//infinity
alert ("5" * 5) ;
alert (True *);
alert (False *); 0
alert (% 5);//1
alert (Infinity% 3);//nan
alert (3 0);//nan
alert (5 % Infinity); 5
alert (0);//0
alert (true%);//1
alert (3 false);//nan
12. In loop
for (var propname in window) {
document.write (propname);
document.write ("<br/>");
}
13, special character comparison
Alert (Null = = undefined); True
alert (null = n = undefined);//false
alert ("Nan" = nan); False
alert ("nan" = = Nan); False
alert (nan = = nan); False
alert (nan = = nan); False
alert (Nan!= nan); True
alert (Nan!== nan); True
alert (false = = 0); True
alert (false = = 0); False
alert (true = = 1); True
alert (true = = 1); False
alert (null = = 0); False
alert (undefined = 0); False
alert (5 = = "5"); True
alert (5 = = "5"); False
14. Boolean Object
var message = "Hello world!";
var Messageasboolean = Boolean (message);
alert (Messageasboolean); True
15, for loop and label used together
both the break statement and the continue statement can be used in conjunction with tagged statements to return a specific location in the code.
Typically, this is done when there is a loop inside the loop, for example:
var num = 0;
Return to a specific location
outermost: For
(var i=0 i < i++) {for
(var j=0; J < + j) {
if (i = = 5 && ; j = = 5) {break
outermost;
}
num++
}
}
alert (num); 55
In the example above, the label outermost represents the first for statement. Normally, each for statement executes 10 blocks of code, which means that num++ is normally executed 100 times, and when execution completes, NUM should equal 100. The break statement here has a parameter, which is the label of the statement that you want to jump to after you stop the loop. This break statement not only jumps out of the internal for statement (that is, using the statement of the variable J), but also jumps out of the external for statement (that is, the statement using the variable i). Therefore, the last value of NUM is 55, because when I and J are equal to 5 o'clock, the loop terminates.
You can use the Continue statement in the same way:
var inum = 0;
Outermost: For
(Var i=0, i<10; i++) {for
(var j=0; j<10; J + +) {
if (i = = 5 && J = = 5) {
continue outermost;
}
inum++
}
}
alert (inum); Output "95"
In the example above, the continue statement forces the loop to continue, not only the internal loop, but also the outer loop. This occurs when J equals 5 o'clock, which means that the internal loop will decrease by 5 iterations, resulting in a inum value of 95.
tip: You can see that the tagged statements used in conjunction with break and continue are very powerful, but overuse of them can cause trouble with debugging code. Be sure to use a label that is descriptive and do not nest too many layers of loops.
The above is today's JavaScript learning Summary, and will continue to update every day, I hope you continue to pay attention.