Home  >  Article  >  Web Front-end  >  What are the operators of javascript

What are the operators of javascript

青灯夜游
青灯夜游Original
2022-02-16 12:00:252765browse

Operator, also known as "operator", is a symbol used to tell the JavaScript engine to perform a certain operation. For example, the plus sign " " means to perform addition operations, and the minus sign "-" means to perform subtraction operations, etc. JavaScript operators include arithmetic operators, bitwise operators, assignment operators, comparison operators, etc.

What are the operators of javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

javascript Operator

Operator, also known as "operator", is a symbol used to tell the JavaScript engine to perform a certain operation. For example, the plus sign " " means execution Addition operation, the minus sign "-" means performing subtraction operation, etc.

JavaScript operators apply to many values, such as strings, numeric values, Boolean values, and even objects. When applied to an object, the corresponding operator will call the object's valueOf() and/or toString() methods to obtain the operable value.

Arithmetic operators

Arithmetic operators are used to perform common mathematical operations, such as addition, subtraction, multiplication, division, etc. The following table lists the support in JavaScript Arithmetic operators:

##Addition operatorx y means calculating the sum of x plus y##-*/%
Operator Description Example
Subtraction operator x - y means to calculate the difference of x minus y
Multiplication operator x * y means to calculate the product of x times y
Division operator x / y means calculating the quotient of x divided by y
Modulo (remainder) operator x % y means calculating the remainder of x divided by y
Assignment operation The


assignment operator is used to assign values ​​to variables. The following table lists the assignment operators supported in JavaScript:

Operator=Comparison operator is used to compare the expressions on the left and right sides of the operator. The result of the comparison operator is a Boolean value. There are only two results, either true or false. . The comparison operators supported in JavaScript are listed in the following table:
Description Example
The simplest assignment operator, assigns the value on the right side of the operator Giving the variable x = 10 to the left side of the operator means assigning the variable Assigning a value to the variable on the left side of the operator x = y is equivalent to x = x y
-= First perform the subtraction operation, and then add the result Assigning a value to the variable on the left side of the operator x -= y is equivalent to x = x - y
*= . Perform multiplication first, Then assign the result to the variable on the left side of the operator x *= y is equivalent to x = x * y
/= Proceed first Division operation, and then assign the result to the variable on the left side of the operator x /= y is equivalent to x = x / y
%= First perform the modulo operation, and then assign the result to the variable on the left side of the operator x %= y is equivalent to x = x % y
Comparison operator

Operator

Name

Example##>=greater than or equalx >= y means if x is greater than or equal to y, then true 31665d41ed5aa5fd619ae7f61a4db94b>
== equals x == y means true if x equals y
=== Congruent x === y means true if x is equal to y, and x and y are also of the same type
!= Not equal x != y means if x is not equal to y, it is true
!== Incomplete etc x !== y means it is true if x is not equal to y, or if x and y have different types
389d82fab9ee17e83bcacccc874bb3a6 greater than x > y means true if x is greater than y
Bitwise right shift (signed right shift): Move all binary bits uniformly to the right by the specified number of bits, and copy the leftmost bit to fill the left side 5 >> 1 is equivalent to 0101 >> 1 The result is 0010, the decimal result is 2
>>> Press Bit right shift by zero (unsigned right shift): Shift all binary bits to the right by the specified number of bits, and add 0 to the far left 5 >>> 1 is equivalent to 0101 > >> The result of 1 is 0010, and the decimal result is 2

Increase and decrement operators

Increase and The auto-decrement operator is used to perform auto-increment (1) and auto-decrement (-1) operations on the value of a variable. The following table lists the auto-increment and auto-decrement operators supported in JavaScript:

Operator Name Affect
x Increment operator Add 1 to x, and then return the value of x
x Increment operator Return the value of x, and then add x 1
--x Decrement operator Decrease x by 1 and then return the value of x
x-- Decrement operator Returns the value of x, then decrements x by 1

Ternary operator

The ternary operator (also known as the conditional operator) consists of a question mark and a colon. The syntax format is as follows:

条件表达式 ? 表达式1 : 表达式2 ;

If "conditional expression If the result of "expression" is true (true), then the code in "expression 1" will be executed, otherwise the code in "expression 2" will be executed.

Explanation: String operations

The and = operators in JavaScript can not only perform mathematical operations, but also Can be used to splice strings, where:

  • The operator means splicing the strings on the left and right sides of the operator together;

  • The = operator means to concatenate strings first, and then assign the result to the variable on the left side of the operator.

[Related recommendations: javascript learning tutorial]

The above is the detailed content of What are the operators of javascript. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn