JavaScript enhancement tutorial-JavaScript Operators

Source: Internet
Author: User
Main introduction: JavaScript reinforcement tutorial-JavaScript operator JavaScript Arithmetic Operator this article is an official HTML5 training tutorial for H5EDU institutions, mainly about: JavaScript reinforcement tutorial-JavaScript Operator
JavaScript Arithmetic Operators

Arithmetic Operators are used to perform operations on two variables or values.

Assign a value of y = 5. The following table describes the use of arithmetic operators:

Example of the operator Description: an online instance with the y value x value
+ Addition x = y + 2 y = 5 x = 7 instances
-Subtraction x = y-2 y = 5 x = 3 instances
* Multiplication x = y * 2 y = 5 x = 10 instances
/Division x = y/2 y = 5 x = 2.5 instances
% Remainder x = y % 2 y = 5 x = 1 instance
++ Auto-increment x = ++ y = 6 x = 6 instances
X = y ++ y = 6 x = 5 instances
-- Auto-Subtract x = -- y = 4 x = 4 instance
X = y -- y = 4 x = 5 instances

For Arithmetic Operators, read our JavaScript operator tutorial.

JavaScript assignment operator

The value assignment operator is used to assign values to JavaScript variables.

Given x = 10 and y = 5, the following table describes the assignment operators:

Operator example Same As x value online instance
= X = y x = 5 instances
+ = X + = y x = x + y x = 15 instances
-= X-= y x = x-y x = 5 instances
* = X * = y x = x * y x = 50 instances
/= X/= y x = x/y x = 2 instance
% = X % = y x = x % y x = 0 instance

For the value assignment operator, you can read our JavaScript operator tutorial.

JavaScript string Operator

+ Operator, + = operator can be used to connect strings.

Given text1 = "Good", text2 = "Morning", and text3 = "", the following table illustrates the use of string operators:

Operator example: text1 text2 text3 online instance
+ Text3 = text1 + text2 "Good" "Morning" "Good Morning" instance
+ = Text1 + = text2 "Good Morning" "Morning" instance
Comparison Operators

Comparison operators are used to determine logical statements to determine whether the given two values or variables are equal.

Given x = 5, the following table shows the usage of comparison operators:

Operator description comparison result online instance
= X = 8 false instance
X = 5 true instance
===The value and type are equal (constant =) x = "5" false instance
X = 5 true instance
! = Not equal to x! = 8 true instances
! = Values and types are not equal to (not always equal to) x! = "5" true instance
X! = 5 false instances
> Greater than x> 8 false instances
<Less than x <8 true instance
> = Greater than or equal to x> = 8 false instance
<= Less than or equal to x <= 8 true instance

For more information about comparison operators, see our JavaScript comparison operators tutorial.

Conditional Operators

Conditional operators are used for conditional assignment.

Given x = 6 and y = 3, the following table demonstrates the operation of conditional operators:

Syntax example online instance
Variable = (condition )? Value 1: Value 2 voteable = (age & 18 )? "Too young": "Old enough" instance
Logical operators

Logical operators are used to determine the logical relationship between variables or values.

Given x = 6 and y = 3, the following example demonstrates the use of logical operators:

Operator Description Example
& And (x <10 & y> 1) are true
| Or (x = 5 | y = 5) is false
! Not! (X = y) is true
JavaScript bit operator

Bitwise operators work on 32-bit numbers. Any numeric operation is converted to 32 bits. The result is converted to a JavaScript number.
The operator Description Example is similar to the result decimal.
& AND x = 5 & 1 0101 & 0001 0001 1
| OR x = 5 | 1 0101 | 0001 0101 5
~ Reverse x = ~ 5 ~ 0101 1010 10
^ Exclusive or x = 5 ^ 1 0101 ^ 0001 0100 4
<Left shift/td> x = 5 <1 0101 <1 1010 10
> Right shift x = 5> 1 0101> 1 0010 2

The above is the content of the JavaScript operator in the JavaScript enhancement tutorial. For more information, see the PHP Chinese website (www.php1.cn )!

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.