JavaScript manipulation operators

Source: Internet
Author: User

Operation operators:

var a = 1+ "a" +1+1;console.log (a);

Code Execution procedure: 1+ string a+1+1 = 1a11.

var a = 1+1+ "a" +1;console.log (a);

The comparison operator calculates the method from left to right, and any number type is added to the string equal to the string, because A is a string of all equals 1a11.

var a = 1/0;console.log (a); var B = -1/0;console.log (b);

Result: Code execution process a equals infinity; b equals-infinity;
Infinity(无穷); Infinity虽然是个英文单词,但它是一个数字类型。

var a = 0/0;console.log (a);

Result: a equals nan;
NaN(Not a Number) 0除以0,除不了,不是个数是非数,但非数也算个数。

var a = 1%5;console.log (a);

The result equals: 1;
因为1除以5除不尽,余数1,所以等于1。

var a = 10%5;console.log (a);

Results: 0;
因为10除以5,等于2没有余数,所以等于0;

var a = 1;var B = A + + +1, (A + 1 is assigned to b,a itself plus 1) console.log (b);

Result: b equals 2.
因为“++” 如果放后边是等语句执行完再自身加1。

var a = 1;var B = ++a + 1; (a itself plus 1 equals 2, plus 1) console.log (b);

Result: b equals 3.
因为“++”如果放前边是先自身加1在执行语句。

var a = 1;var B = ++a + 1; (a itself plus 1 equals 2, plus 1) console.log (b);

Add:
a+=10 = = = A+10;
Priority: "=" The Weakest, "()" has the highest priority.

Little Practice One:

var a = (3-5/6 + 1)%2;var B = 3;    b%= A + 3;    document.write (a++);    document.write (--b);

Little Exercise Two:

var a = 123;var B = 234;

The values of A and B are interchanged without creating new variables.


If there is a misunderstanding in the text, please point out the criticism ~ (≧▽≦)/~

JavaScript manipulation operators

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.