JavaScript Learning Notes Grooming (operator)

Source: Internet
Author: User

1. The combination of operators and operands is called an expression.

2. Arithmetic operator (+-*/% a++ A----a ++a)

a.+

1. For numerical calculation: Var a=1;var b=2;alert (a+b) ===3

2. For string connection: Var a= ' h '; var b= "w"; alert (a+b) ==HW

Any data type and string addition are strings * * *

var a= ' h '; var b=1;alert (a+b) = = ' H1 '

b.%

1. Used to take a range of values (* Take an even number.) * * Take odd numbers)

2. Generally not used for decimals because the results are indeterminate

c.a++ (+ + in the back, first to assign value, add it yourself; a=1;b=a++;b=1)

D.++a (--in front, add first, then assign value; a=1;b=++a;b=2)


3. Relational operators (comparison operators) [< > <= >= = = = = =!==]

1. The result of the operation is a Boolean value (Ture;false)

2. All strings are converted to ASCII and then compared; multiple strings are only the first, the first equals the next. var a= ' ABV '; var b= ' ABA '; alert (a>b); result ture.

ASCII code: A=A; B=b; v>a;

3. Normal comparison of values

4. When one is a string, one is a numeric value, the string is converted to a numeric type, then compared, and if it cannot be converted to a numeric type, Nan is returned and false is returned.

5.unfinished NULL

6. If two are numeric strings, then they are only the first one.

var a= ' 223 '; var b= ' + '; alert (a>b); = = False

7. Comparing a value to a Boolean value, the Boolean value is converted to a value and then compared. False=0;true=1

  Note:= = only compare values are equal

1. Compare ASCII code values when comparing strings

2. Compare two values to compare whether their values are equal

3. When comparing functions, it is to determine whether their positions are equal

  Note:= = = Not only compares values, but also compares type equality

3. Assignment operator (= + = = *=/=%=)

1.+=

1. Adding and re-assigning Var a=1;a+=2;a=3 for numeric values

2. Assigning values to string connections

  Note: any data type and string addition are equal to the added string

4. Logical operator (Boolean operator) [with and && or or | | non-not!]

A&&b two are true, only to return to true

a| | b One of them is true, it returns to True

! A take the reverse, false change true, true change false

1. You can perform operations on any type of data and convert it to the corresponding Boolean value.

Undefined:false

Null:false

Boolean: Is the value of itself

Number: Except that 0 thought it was true.

String: Except for the empty string, I think it's true.

Object: True

2. Assigning values to class variables

var a = b && c

If one operand is an object and the other is a Boolean value, the object is returned.

If the two operands are objects, the second object is returned.

Returns null if one of the operands is null.

If an operand is Nan, a nan is returned.

If an operand is undefined, an error occurs.

    The logical operators---detailed!

5. Unary operators

typeof +-Delete new + +--

A. + Plus, positive

B.delete methods or properties for deleting objects

C.new used to create an object

6. Special operators

A. To declare multiple variables at once

B. ()

1. When the operation has a priority function A * (B-C)

2. Run a function

C. Ternary operators (Assign values to variables conditionally based on the results of an expression)

Format: var variable = Boolean expression? Truth: False value

var c=a>b?a:0;

7. Bitwise operator ( not very understand this, forget the big God pointing pointing )

JavaScript Learning Notes Grooming (operator)

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.