JavaScript operators (relational operators, equality operators, and conditional operators)

Source: Internet
Author: User

The relational operator is used to compare two values and return a Boolean value. Relational operators include greater than (>), less than (<), greater than or equal (>=), and less than or equal (<=). When the relational operator is used for a non-numeric value, the conversion of the numeric value is also performed first. such as Var result=5>3;

1. Attempt to convert two operators to numbers;

2. If all two operators are strings, the comparison of strings

3. Returns False if either expression is Nan;

4.-0 equals +0;

5. Negative infinity is less than any number that contains itself

6. Positive infinity is greater than any number that contains itself

An equality operator that determines whether two variables are equal. The equality Comparison of string, numeric, and Boolean values is simple, and the comparison of objects is complex. Equal and unequal, first converted to the same type, and then compared. Congruent and not congruent, do not convert, directly to compare.

1. Equality and inequality

The equality operator consists of two equal signs (= =) and returns True if the two operands are equal. Inequality consists of an exclamation point and an equal sign (! =), returns True if the two operands are not equal. This two operator will convert the type first and then compare it.

If the types of two expressions are different, try converting them to a string, number, or Boolean value, and Nan is not equal to any value including itself;

Negative 0 equals positive zero, nul is equal to null and undefined;

The following conditions are considered equal: the same string, the number of equal numbers, the same object, the same Boolean value, or a value that can be cast to one of the above conditions when the type is not.

2. Congruent and non-congruent

The equality operator consists of 3 equal signs (= = =), not the equality operator (! = =). Congruent and not congruent with the same as above, but not the type of conversion.

such as Var result= null===undefined;//false var num= "" "==55;//true var num1=" "===55;//false

The conditional operator is a ternary operator, which is similar to the conditional operator in Java. The format is as follows

Test? Expression1:expression2
var num=5>3?5:3; Console.log (num); // Output 5

The assignment operator consists of an equal sign (=), which assigns the value on the right to the variable on the left. It also contains some complex assignment operators, such as *=,+=,-=,/=,%=.

var num=10;

Num%=2 equals num=num%2;num*=2;num+=3;num/=3;num-=2;

The comma operator, using the comma operator, can perform multiple operations in a single statement, such as Var num=12,num2=13;

JavaScript operators (relational operators, equality operators, and conditional operators)

Related Article

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.