1. Operators:
1.1 + (addition, positive number, connector)
True is 1. False is 0
var a = 1;document.write ((1+true) + "<br/>");d Ocument.write ((1+false) + "<br/>");d ocument.write ("Hello" + 1); Hello1
1.2/Division
Because JS has only number type, so two integers can not be integers when the result is a decimal
var a = ten; var b = 3; document.write ("Division operation is:" + (A/b) + "<br/>"); If two integers are not integers, the result is a decimal.
1.3 Comparison operators
The rules for comparing strings to strings are:
Case 1: You can find different characters in the corresponding position, then compare the size of the first different character.
Case 2: Cannot find the different characters on the corresponding position, this time compares the length of two strings.
Note: When a string is compared to a number, the string is converted to a number before being compared
document.write ("10 greater than 3?") "+ (10>3) +"<br/>"); document.write ("10 String greater than 3 string?") "+ (" > ") +"<br/>"); String compared to string document.write ("10 is greater than string 9?"). "+ (> 9") + "<br/>"); /* strings can also be compared to numbers. When a number is compared to a string, the string is converted to a number before being compared.
1.4 Logical operators
Only && | |
1.5 Three mesh operator
Boolean expression? value 1: Value 2;
2. Control process
2.1if statements
Format:
if (judging condition) {
Code that meets conditional execution
}
The special point of the IF statement:
1. The If statement condition in JavaScript can not only write Boolean expressions, but also write any data.
Number not 0 is true and 0 is false.
String content cannot be NULL is true, the content is false when empty.
Undefined:false (but must first be defined beforehand)
Nan:false
2.2 SELECT statement:
Switch statement
Switch (variable) {
Case value 1:
Break
Case Value 2:
Break
Case Value 3:
Break
.....
Default
Break
}
The Special place:
1. In JavaScript, a case can be followed by a constant and a variable can also be followed by an expression.
var option = "A"; var a = "a"; VAR score =98; Switch (option) {case score>=90? " A ":" B ": document.write (" Java "); break; Case "B": document.write ("PS"); Case "C": document.write ("JavaScript"); break; Case "D": document.write ("C + +"); break; }
Java Operators and Control statements