当前位置:网站首页>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 .
边栏推荐
- Usage of in in SQL DQL query
- [leetcode] 502.ipo (difficult)
- How many bytes does Boolean occupy?
- JS interview questions
- Victoriametrics single node of kubernetes
- It's over. I went to work for three months and became bald
- 什么是分区分桶?
- Data quality: the core of data governance
- About vscode usage+ Solutions to the problem of tab failure
- Use of hyperlinks
猜你喜欢

The third day of Xiaobai programmer

核电站在席卷欧洲的热浪中努力保持安全工作

力矩电机控制基本原理

Ffmpeg plays audio and video, time_ Base solves the problem of audio synchronization and SDL renders the picture

『SignalR』. Net using signalr for real-time communication

Randomly generate 10 (range 1~100) integers, save them to the array, and print the array in reverse order. And find the average value, the maximum value and the subscript of the maximum value, and fin

Use of hyperlinks

All you want to know about interface testing is here

Visitor mode

什么是分区分桶?
随机推荐
Wechat official account application development (I)
D3.js learning
Leetcode 106. 从中序与后序遍历序列构造二叉树
Smart S7-200 PLC channel free mapping function block (do_map)
El expression improves JSP
The dragon lizard exhibition area plays a new trick this time. Let's see whose DNA moved?
Why is the integer type 128 to byte -128
Flex layout
[assembly language 01] basic knowledge
『Skywalking』. Net core fast access distributed link tracking platform
mysql: error while loading shared libraries: libncurses.so. 5: cannot open shared object file: No suc
聚名十年,说出你的故事,百万豪礼等你拿
SQL基本语句 DQL select与提取 DML插入删除
It's over. I went to work for three months and became bald
JMeter websocket interface test
淦,为什么 '𠮷𠮷𠮷' .length !== 3 ??
平台架构搭建
Why does redis choose single thread?
Xiaobai programmer's fifth day
Use of hyperlinks