Getting Started with JavaScript · JavaScript has a full range of operators _ basics

Source: Internet
Author: User
Tags bitwise

Compound assignment operator

operator symbols
Addition +=
Bitwise AND &=
by bit or |=
Per-bitwise XOR OR ^=
Division /=
Move left <<=
Take the mold %=
Multiplication *=
Move right >>=
Subtraction -=
No sign Right move >>>=

Requirements

Version information

Conditional (triple-mesh) operator (?:)

Executes one of two statements according to a condition.

test ? Statement 1 : statement2

Parameters

Test

Any Boolean expression.

Statement 1

The statement to execute when test is true . Can be a compound statement.

Statement 2

The statement to execute when test is false . Can be a compound statement.

Description

?: operator is a shortcut to a if...else statement. It is often used as part of a larger expression, and it is not consistent to use the if...else statement here. For example:

var now = new Date();
? " evening." : " day.");

In this example, if it is 6pm, a string containing the "good evening." is created. The equivalent code for using the if...else statement is as follows:

var now = new Date();
var greeting = "Good";
if (now.getHours() > 17)
greeting += " evening.";
else
   greeting += " day.";

Requirements

Version 1

Please see

If...else Statement | Operator Precedence | Operator Summary

Delete operator

Deletes an attribute from the object, or deletes an element from the array.

delete expression

The expression parameter is a valid JScript expression, usually a property name or an array element.

Description

Returns falseif the result of the expression is an object and the property specified in expression exists and the object does not allow it to be deleted.

In all other cases, returns true.

Requirements

Version 3

Please see

Operator Precedence | Operator Summary

Division assignment operator (/=)

The variable value is divided by the expression value, and the result is assigned to the variable.

result /= expression

Parameters

Result

Any numeric variable.

Expression

Any numeric expression.

Description

Using the /= operator is equivalent to using the following statement:

result = result / expression

Requirements

Version 1

Please see

/operator | Operator Precedence | Operator Summary

Division operator (/)

Divides the values of two expressions.

result = number1 / number2

Parameters

Result

Any numeric variable.

Number1

Any numeric expression.

Number2

Any numeric expression.

Requirements

Version 1

Please see

/= operator | Operator Precedence | Operator Summary

In operator

The attribute is present in the test object.

result = property in object

Parameters

Result

Required option. Any variable.

Property

Required option. An expression that is equivalent to a string expression.

Object

Required option. Any object.

Description

The in operation checks whether the object is named property. You can also examine the object's prototype to see if the property is part of the prototype chain.

Requirements

Version 1

Please see

Operator Precedence | Operator Summary

Increment (+ +) and decrement (-) operators

The value of the variable is incremented by one or descending one.

Syntax 1

result = ++variable
result = --variable
result = variable++

result = variable--

Syntax 2

++variable
--variable
variable++

variable--

Parameters

Result

Any variable.

Variable

Any variable.

Description

Increment and decrement operators, which are shortcuts for modifying values in existing variables. The value of an expression that contains one of these operators depends on whether the operator is preceded by a variable or after a variable:

var j, k;
k = 2;
++k;

Because increment occurs before the expression is evaluated, the value 3 is assigned to J.

Compared with the following example:

var j, k;
k = 2;
j = k++;

Here, because the increment occurs after the expression is evaluated, the value 2 is assigned to J.



JavaScript has a full range of operators, including arithmetic, logic, bits, and assignment operators. In addition, there are some other operators.

Compute Logical Bitwise OPERATIONS Assignment Miscellaneous
Descriptive symbols
Negative
Logic is not!
Take the counter by the position
Assign value =
Remove Delete
Increment + +
Less than <
Press-bit left-shift <<
Operation Assignment Op= typeof
Operator
Diminishing--
Greater than >
Bitwise RIGHT SHIFT >>
void operator void
Multiplication
Less than or equal to <=
Unsigned Right Shift >>>
Division
Greater than or equal to >=
By Bit and &
Modulo operation%
equals = =
Per-bitwise XOR or ^
Addition +
Not equal to!=.
by bit or |
Subtraction
Logic and &&
Logic or | |
condition (ternary operator)?:
Comma
Identity = = =
Bu Heng and other!==

Operators are highly preferred
Operators in JavaScript are evaluated in a particular order. This order is the precedence of the operator. The following table lists these operators by priority from highest to lowest. Operators in the same row are evaluated in order from left to right.

Operator description
. [] () field access, array subscripts, and function calls
++ -- - ~ ! typeof the new void delete unary operator, return data type, object creation, undefined value
*/% multiplication, division, modulo
+-+ addition, subtraction, string concatenation
<< >> >>> Shift
< <= > >= less than, less than, greater than, greater than or equal
=!= = =!== equals, not equal, identity, not identical
& Bitwise AND
^ per-bitwise XOR OR
| by bit or
&& Logic and
|| Logical OR
?: Conditions
= op= Assignment, Operation assignment
, multiple evaluation

Parentheses can be used to change the order of evaluation. An expression in parentheses should be evaluated before it is used for the remainder of the statement.

Operators with higher precedence are evaluated before an operator with a lower precedence level. For example:

z = 78 * (96 + 3 + 45)

There are five operators in the expression: =, *, (), +, and +. Depending on the priority, they are evaluated in the following order: (), *, +, +, =.

First, evaluate the expression in parentheses: there are two addition operators, which have the same precedence: 96 and 3 Add together, then add their sum to 45, and the result is 144.
Then multiply: Multiply by 78 and 144, and the result is 11232.
Finally, the assignment operation: assign 11232 to Z.
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.