Java Operators and Control statements

Source: Internet
Author: User
Tags logical operators

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.