js逻辑运算符有三个:逻辑非!、逻辑与&&、逻辑或||。所谓短路操作就是, 当&&的第一个操作数的值是false时,直接返回第一个操作数的值,不再对第二个操作数进行计算;
var bar1 = 0&&c; console.log('bar1====='+bar1); //bar1=====0 var foo1 = 5&&c; console.log('foo1===='+foo1); //报c is not defined错误。
当||的第一个操作数的值是true时,直接返回返回第一个操作数的值,不再对第二个操作数进行计算;
var foo = 5||c;console.log('foo===='+foo);//foo====5 不报错var bar = 0||c;console.log('bar===='+bar);//报c is not defined错误。
相关推荐:
以上就是关于逻辑运算符短路解析的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号