javascript - 在 javascript 中使用 while 循环有什么副作用?
问题描述
这两个 javascript while 循环是完全一样的。但是,一旦我们在其中一个之后删除 'console.log('end')',它会在 Chrome 控制台和 Node.js v14.8.0 中吐出额外的 '41' 数字。这就是所谓的“副作用”吗?
// While-loop 1
const max = 40, min = 30;
let i = min + 1;
while (i < max) {
console.log(i);
i += 2;
}
console.log('end');
// 31 33 35 37 39
// While-loop 2
const max = 40, min = 30;
let i = min + 1;
while (i < max) {
console.log(i);
i += 2;
}
// 31 33 35 37 39 41
解决方案
推荐阅读
- java - 用于 CompositeKey 最低要求的 Spring JPA @IdClass
- javascript - 如何使用 jest 在 typescript 中模拟函数类型
- java - 为 Spring Boot 应用程序部署新功能的最佳实践是什么?
- mysql - 如何编写这样的 SQL
- hibernate - 数据异常:字符串数据,右截断错误
- java - 如何以通用方式使用算术运算减少原始数组?
- java - 无法解决端点响应的符号错误
- c# - 客户端仅接收 1440 字节的流
- python - 由于阶段故障而中止作业:将 spark 数据帧转换为 Pandas 数据帧时
- c# - 实体框架核心:外键已设置并被召回为空