Introduction to Javascript Article 3 js operations page 1/2

Source: Internet
Author: User

1, expression:
The simplest expression: the direct amount or variable name. Var a = 1;
Value of the direct expression: itself.
Variable expression value: the value that the variable stores or references.

2, operator:
Unary operator: for example,-3
Binary operators: for example, 3 + 4
Ternary operators: such? :

Problems frequently encountered by beginners:
Increment operator:
For example:
I = 1;
J = ++ I; // increment the number of operations first, and then calculate.
// Output I = 2; j = 2;

I = 1;
J = I ++; // then, the incremental operation is performed, that is, the calculation is performed first, and then the number of operations is incremented.
// Output I = 2; j = 1;

3. Equal operators:
=: Value assignment operator;
=: Equal operator;
===: Equivalent operator;
The value NaN will never be equal to any value, including itself.
Alert (NaN = NaN); // false NaN indicates Not a Number
To check whether a value is NaN, you can use the global function isNaN ();

Note the following for beginners:
Var a = [1, 2, 3];
Var B = [1, 2, 3];
Document. write (a = B); // output false. (This is actually the content of Chapter 1 .)
// Although the values are the same, the types are the same, but the addresses are different.
--------------------------------------------------------
Var a = [1, 2, 3];
Var B =;
Var c =;
Document. write (B = c); // Output true;
--------------------------------------------------------
Var a = "1 ";
Var B = true;
Document. write (a = B); // Output true
Document. write (a = B); // the output value is false. The values are the same and the types are different.

4. Comparison operators:
It should be noted that the string is to be cut and compared.
It is case sensitive.
If your requirement is case insensitive:
You can use String. toLowerCase () // lowercase only
String. toUpperCase () // convert it in uppercase and then compare it.

5, in OPERATOR:
Note that the value on the left is the property of the object on the right.
For example:
Var a = {x: 1, y: 2 };
Var B = "x" in a; // true
Var c = "toString" in a; // true. The value on the left is the attribute of the object on the right.

6 instanceof OPERATOR:
Note that the Operation number on the left is an object, and the operation number on the right is the name of the object class.
For example:
Var a = new Date ()
A instanceof Date; // true
A instanceof Object; // true
A instanceof Number; // false

7, 3 element conditional operators:
Note that the first operation must be a Boolean value.
X> 0? 3: 2;

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.