JavaScript self-increment, decrement operator

Source: Internet
Author: User

JavaScript self-increment, decrement operator, and expression syntax
vari++;
    • var--Declaring variables
    • i--Variable name
    • ++--Self-increment operator
JavaScript self-increment, decrement operator and expression
JavaScript self-increment, decrement operator and expression (I initial value is 6)
Operator ++i --i i++ i--
Name Pre-increment operator Pre-decrement operator Post-increment operator Post-decrement operator
An expression ++i -I. i++ i--
Example ++i; I.; i++; i--;
Results of I 7 5 7 5
An interesting example ++i
Alert (i)
Alert (++i)
Alert (i)
-I.
Alert (i)
Alert (-I.)
Alert (i)
i++
Alert (i)
Alert (i++)
Alert (i)
i--
Alert (i)
Alert (i--)
Alert (i)
Results 7
8
8
5
4
4
7
7
8
5
5
4
Example explanation

The pre-increment operator is essentially different from the post-increment operator, where the same point is 1 for itself, and the difference is that the former increment operator is preceded by 1, then the operand value, and the increment operator is the value of the operand first, plus 1. For example:

var a;var i=6;//(前加加)i加1后,i等于7,并将i值赋予a,于是a等于7a=++i;document.write(i);document.write(a);i=6;//(后加加)将i值赋予a,于是a等于6,最后i加1,i等于7a=i++;document.write(i);document.write(a);

Results

7776
Original link: http://www.cnblogs.com/leejersey/archive/2011/12/12/2284468.html

JavaScript self-increment, decrement 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.