JavaScript basic Syntax-operator

Source: Internet
Author: User
Tags arithmetic operators

Two javascript02 basic syntax-operators

(i) Arithmetic operators: plus (+), minus (-), multiply (*), divide (/), remainder (%)

* Add, subtract, multiply, divide, remainder, and arithmetic in mathematics for example: 9/2=4.5,4*5=20,9%2=1

*-In addition to representing a minus sign, you can also indicate a minus sign for example: X=-y

* + In addition to the connection can be used to indicate that the addition operation can also use strings for example: "abc" + "def" = "abcdef"

PS: By forcing a type conversion, the plus sign can also concatenate variables of different types and perform different operations by converting to a number or string:

Number + String: Number + String Example: "abc" = "3abc"

Number + Boolean: true?1,false?0 for example: 4+true=5

String + Boolean: Boolean value? string "true" and "false" for example: "Is" +true= "is true"

(ii) Logical operators

* Logical operators are primarily used to select conditional expression operations in control statements and loop control statements , for example: (i>=3) && (i<=8) indicates that I is both greater than or equal to 3 and less than or equal to 8.

* Conditional expressions result in two types: true (True) and False (false). If there are multiple conditional expressions, then multiple expressions can be connected with, or and non-equal logical operators;

Two expressions if all are true, then the result of the operation is also true, as long as there is a false result of the operation is false.

* precedence over or precedence of logical operations is higher, and in the same case first the operation is followed by the relational expression and then the relational expression.

(c) Bitwise arithmetic

* Shift: 3<<2 first converts 3 to 2 binary 11, then left 2 bits, the right empty out of 0 to 2, and 1100 in 10, 12.

That is, moving the N-bit to the left is equal to multiplying 2^n

* Bit non: ~1=~01 (2 binary) "" 10 (2 binary) =2

* Bit with (&), bit or (|), XOR (^)

JavaScript basic Syntax-operator

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.