当前位置:网站首页>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 .
边栏推荐
- 完啦,上班三个月,变秃了
- Use of hyperlinks
- Based on if nesting and function call
- Call of addition, subtraction, multiplication and division of integer type only
- What have I experienced to become a harder tester than development?
- 【PMP学习笔记】第1章 PMP体系引论
- SQL中in的用法 DQL 查询
- How to resolve a domain name to multiple IP addresses?
- Compile and decompile
- Xiaobai programmer's seventh day
猜你喜欢

About vscode usage+ Solutions to the problem of tab failure

All you want to know about interface testing is here

Whether the five distribution methods will produce internal fragments and external fragments

Perform Jieba word segmentation on the required content and output EXCEL documents according to word frequency

Basic principle of torque motor control

3dslicer import cone beam CT image

Flex layout

Xiaobai programmer's seventh day

MySQL - subquery - column subquery (multi row subquery)

『Skywalking』.NET Core快速接入分布式链路追踪平台
随机推荐
mysql: error while loading shared libraries: libncurses.so. 5: cannot open shared object file: No suc
Gan, why '𠮷 𠮷'.Length== 3 ??
Xiaobai programmer's seventh day
Application of breakthrough thinking in testing work
三菱FX PLC自由口RS指令实现MODBUS通讯
Use of hyperlinks
What is redis? Briefly describe its advantages and disadvantages
About vscode usage+ Solutions to the problem of tab failure
Wechat applet application development competition works comprehensive development record - Jinlu cultural tourism (cloud development - Overview)
Xiaobai programmer's first day
MySQL --- 子查询 - 列子查询(多行子查询)
What should I do if I encounter the problem of verification code during automatic testing?
数据库进阶·如何针对所有用户数据中没有的数据去加入随机的数据-蜻蜓Q系统用户没有头像如何加入头像数据-优雅草科技kir
【C语法】void*浅说
Nuclear power plants strive to maintain safety in the heat wave sweeping Europe
Recursive case -c
ML-Numpy
Xiaobai programmer the next day
vim用法记录
Xiaobai programmer's sixth day