当前位置:网站首页>Explore the use of self increasing and self decreasing operators
Explore the use of self increasing and self decreasing operators
2022-07-25 22:24:00 【Ultimate xiaoteng】
List of articles
1. introduction
Increment operator ( ++ ) And decrement operators ( – )
To distinguish x++ and ++x So I write this article .
2. use JavaScript Code implementation
Self increasing operation
// Self increasing , Self increase means adding 1 Figures obtained
var x = 5;
x++;//x++ Equate to x = x + 1;
console.log(x);// The result is 6
// X++ And ++x There are two uses
var a1 =5 , a2 = 5 ;
var b;
var c;
b=a1++;
c=++a2;
console.log(b);// Output 5
console.log(c);// Output 6
console.log(a1);// Output 6
console.log(a2);// Output 6
Through the above code, we can find , Variable value is 5, No matter through Variable ++ still ++ Variable , The values of variables are added by themselves 1, But there are differences when assigning values to other variables in the process of self addition .
In fact, we don't need to know the underlying principle of the code , There is a rule to remember , Who is close to the right of the equal sign , Just use who .
for example ,s = x++ To the right of this equal sign is the variable , Then assign a value to the variable first ;( First use then add )s = ++x To the right of this equal sign is a plus sign , Then calculate self addition first , Get the result and assign value ;( Add first and then use )
The same is true of self subtraction
var x1 =9 , x2 = 9 ;
var y;
var z;
y=x1--;
z=--x2;
console.log(y);// Output 9
console.log(z);// Output 8
console.log(x1);// Output 8
console.log(x2);// Output 8
Who is close to the right of the equal sign , Just use who .s = x-- To the right of this equal sign is the variable , Then assign a value to the variable first .( Use first and then subtract )s = --x To the right of this equal sign is a minus sign , Then calculate self subtraction first , Get the result and assign value .( First reduce and then use )
3. Summary
The overall difference is - - -( Operation before use ) And - - -( Use first and then calculate ) The difference between .
Practice and you will be impressed .
边栏推荐
- QML module not found
- Get together for ten years, tell your story, millions of gifts are waiting for you
- JSP nine built-in objects
- 微信发卡小程序源码-自动发卡小程序源码-带流量主功能
- Nuclear power plants strive to maintain safety in the heat wave sweeping Europe
- Call of addition, subtraction, multiplication and division of integer type only
- xxl-job中 关于所有日志系统的源码的解读(一行一行源码解读)
- VIM usage record
- Using simple scripts to process data in 3dslicer
- MySQL - subquery - column subquery (multi row subquery)
猜你喜欢

JMeter websocket interface test

Arcgis10.2 configuring postgresql9.2 standard tutorial

Ts:typera code fragment indentation display exception (resolved) -2022.7.24

H5幸运刮刮乐抽奖 免公众号+直运营

还不懂mock测试?一篇文章带你熟悉mock

About vscode usage+ Solutions to the problem of tab failure

3dslicer importing medical image data

After 2 years of functional testing, I feel like I can't do anything. Where should I go in 2022?

如何将一个域名解析到多个IP地址?

Playwright tutorial (II) suitable for Xiaobai
随机推荐
面向领域模型编程
torchvision
Interpretation of the source code of all logging systems in XXL job (line by line source code interpretation)
Xiaobai programmer day 8
Perform Jieba word segmentation on the required content and output EXCEL documents according to word frequency
6-18 vulnerability exploitation - backdoor connection
How is it most convenient to open an account for stock speculation? Is it safe for online account managers to open an account
访问者模式(visitor)模式
Wechat applet application development competition works comprehensive development record - Jinlu cultural tourism (cloud development - Overview)
3dslicer importing medical image data
Redis memory elimination mechanism?
Using simple scripts to process data in 3dslicer
MySQL - subquery - column subquery (multi row subquery)
JS interview questions
3dslicer import cone beam CT image
If it is modified according to the name of the framework module
淦,为什么 '𠮷𠮷𠮷' .length !== 3 ??
Ffmpeg plays audio and video, time_ Base solves the problem of audio synchronization and SDL renders the picture
ArcGIS中的WKID
数据库进阶·如何针对所有用户数据中没有的数据去加入随机的数据-蜻蜓Q系统用户没有头像如何加入头像数据-优雅草科技kir