Getting started with JavaScript & #183; JavaScript has full-range Operators

Source: Internet
Author: User

Compound assignment operator

Operator Symbol
Addition + =
Bitwise AND & =
By bit or | =
Bitwise OR ^ =
Division /=
Move left <=
Modulo % =
Multiplication * =
Right Shift >>=
Subtraction -=
Unsigned right shift >>>=

Requirements

Version Information

Condition (three orders) operator (? :)

Execute one of the two statements according to the conditions.

test ? Statement1 : Statement2

Parameters

Test

Any Boolean expression.

Statement 1

WhenTestYesTrueStatement. It can be a compound statement.

Statement 2

WhenTestYesFalseStatement. It can be a compound statement.

Description

? :Operator isIf... elseStatement shortcut. It is usually used as part of a larger expression, and used hereIf... elseThe statement is not coordinated. For example:

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

In this example, if it is after 6, a string containing "Good evening." is created. UseIf... elseThe equivalent code of the statement is as follows:

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

Version 1

See

If... else statement | Operator priority | Operator Summary

Delete Operator

Deletes an attribute from an object or an element from an array.

delete expression

ExpressionA parameter is a valid JScript expression, usually an attribute name or an array element.

Description

IfExpressionThe result is an object, andExpressionIf the specified attribute exists and the object cannot be deletedFalse.

In all other casesTrue.

Requirements

Version 3

See

Operator priority | Operator Summary

Division assignment operator (/=)

Divide the variable value by the expression value and assign the result to the variable.

result /= expression

Parameters

Result

Any numeric variable.

Expression

Any numeric expression.

Description

Use/=The operator is equivalent to the following statement:

result = result / expression
Requirements

Version 1

See

/Operator | Operator priority | Operator Summary

Division operator (/)

Divide the values of two expressions.

result = number1 / number2

Parameters

Result

Any numeric variable.

Number1

Any numeric expression.

Number2

Any numeric expression.

Requirements

Version 1

See

/= Operator | Operator priority | Operator Summary

In Operator

Whether the property exists in the test object.

result = property in object

Parameters

Result

Required. Any variable.

Property

Required. It is equivalent to an expression of a string expression.

Object

Required. Any object.

Description

InThe operation checks whether the object has a property name. You can also check the prototype of the object to know whether the property is part of the prototype chain.

Requirements

Version 1

See

Operator priority | Operator Summary

Increment (++) and decrease (--) Operators

The variable value increases by one or decreases by 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

The increment and decrement operators are shortcuts for modifying values in variables. The value of the expression that contains one of these operators depends on whether the operator is before the variable or after the variable:

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

Because the increment occurs before the expression is evaluated, value 3 is assignedJ.

Compare with the following example:

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

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



JavaScript has a full range of operators, including arithmetic, logic, bit, and value assignment operators. There are also some other operators.

Calculation logic bit assignment Miscellaneous
Description symbol
Negative value-
Non-logical!
Bitwise inversion ~
Assignment =
Delete
Increment ++
Less than <
Shift left by bit <
Assignment oP = typeof
Operator
Decrease --
Greater than>
Shift right by bit>
Void operator void
Multiplication *
Less than or equal to <=
Unsigned shift to the right >>>
Division/
Greater than or equal to> =
Bitwise AND &
Modulo operation %
Equal to =
By bit or ^
Addition +
Not equal! =
By bit or |
Subtraction-
Logic &&
Logic or |
Condition (ternary operator )? :
Comma,
Constant equal =
Not constant! =

Operator precedence
Operators in JavaScript are evaluated in a specific order. This order is the operator priority. The following table lists these operators at the highest to lowest priority. Operators in the same row are evaluated from left to right.

Operator description
. [] () Field access, array subscript, and function call
++ ---~ ! Typeof new void delete unary operator, returned data type, object creation, undefined Value
*/% Multiplication, division, modulo
+-+ Addition, subtraction, and string connection
<>>>> Shift
<=> = Less than, less than or equal to, greater than, or greater than or equal
=! ===! = Equal to, not equal to, constant, non-Constant
& Bitwise AND
^ Bitwise OR
| By bit or
& Logic and
| Logical or
? : Condition
= OP = value assignment and Operation Value assignment
, Multiple evaluate

Parentheses can be used to change the order of evaluation. The expressions in parentheses should be evaluated before they are used for the rest of the statement.

An operator with a higher priority is evaluated before an operator with a lower priority. For example:

Z = 78*(96 + 3 + 45)

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

Evaluate the expressions in parentheses: There are two addition operators, which have the same priority: 96 and 3, and then add their sum and 45, the result is 144.
Then there is the multiplication operation: multiply 78 and 144, and the result is 11232.
Finally, the value 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.