当前位置:网站首页>通俗易懂地区分++i和i++
通俗易懂地区分++i和i++
2022-07-27 14:39:00 【前行的枫】
平常使用频率最多的就是i++这种变量自增1的形式了。其实如果只是为了让变量i自增1的话,i++和++i的效果是一样的。
var a = 1;
a++;
console.log(a) // 2
var b = 1;
++b;
console.log(b) // 2
··························································
但当需要进行运算时,i++和++i就大有区别了。
··························································
var c = 1;
var result1 = c++ + 2;
console.log(result1) // 3
// 通常的解释:c参与运算后再自增
// 我的解释:确实是这样,但可以这样理解,大佬让c去和2进行对战(运算)
// 然后对战(运算)完后,提升c的等级(自增1)。
var d = 1;
var result2 = ++d + 2;
console.log(result2) // 4
// 通常的解释:d先自增再参与运算
// 我的解释:确实是这样,但可以这样理解,大佬让d去和2进行对战(运算),
// 并让d提升等级(自增1)后再去和2对战,不然打不过。
边栏推荐
- Learn parquet file format
- To meet risc-v challenges? ARM CPU introduces custom instruction function!
- 线程中死锁的成因及解决方案
- Zhaoqi scientific innovation and entrepreneurship competition planning and undertaking organization, mass entrepreneurship and innovation platform, project landing and docking
- scrapy爬虫框架
- 43亿欧元现金收购欧司朗宣告失败!ams表示将继续收购
- [sword finger offer] interview question 53- Ⅱ: missing numbers in 0 ~ n-1 - binary search
- Insert sort directly
- JS uses for in and for of to simplify ordinary for loops
- C language: function stack frame
猜你喜欢

Flask连接mysql数据库已有表

DRF学习笔记(四):DRF视图

NPM install error unable to access

IP protocol of network layer

数组名是首元素地址吗?
![[sword finger offer] interview question 49: ugly number](/img/7a/2bc9306578530fbb5ac3b32254676d.png)
[sword finger offer] interview question 49: ugly number

Network principle (2) -- network development

Using Lombok results in the absence of parent class attributes in the printed toString

Inter thread wait and wake-up mechanism, singleton mode, blocking queue, timer

Mlx90640 infrared thermal imager temperature sensor module development notes (VII)
随机推荐
网络层的IP协议
js操作dom节点
渗透测试-干货 | 80篇+网络安全面试经验帖(面试篇)
IP protocol of network layer
文字批量替换功能
leetcode-1:两数之和
C语言:数据的存储
Causes and solutions of deadlock in threads
[sword finger offer] interview question 45: arrange the array into the smallest number
Under the ban, the Countermeasures of security giants Haikang and Dahua!
Half find
聊聊面试必问的索引
【云享读书会第13期】FFmpeg 查看媒体信息和处理音视频文件的常用方法
DRF学习笔记(五):视图集ViewSet
Modify spark to support remote access to OSS files
Spark Bucket Table Join
C语言实现字节流与十六进制字符串的相互转换
Go language slow start - Basic built-in types
go语言慢速入门——基本内置类型
Spark 3.0 DPP implementation logic