双波浪号
1234 | var i = 5.1;var j = 5.5;console.log(~~i); // 5console.log(~~j); // 5 |
---|
作用类似Math.floor。
类似的意思是在处理正数的时候,如果处理负数就它俩就不同了:
1234 | ~~-5.1 // 5Math.floor(-5.1) // -6~~-5.5 // 5Math.floor(-5.5) // -6 |
---|
注:
Math.ceil(x) Returns the smallest integer greater than or equal to a number. Math.floor(x) Returns the largest integer less than or equal to a number.
双感叹号
12345678 | var a = 1;var b = null;var c = '';var d = 'code';console.log(!!a); // trueconsole.log(!!b); // falseconsole.log(!!c); // falseconsole.log(!!d); // true |
---|
作用类似Boolean,把值转换为boolean值。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有