JavaScript中双符号的运算详解
网络编程 2021-07-04 19:20www.168986.cn编程入门
这篇文章主要给大家介绍了JavaScript中双符号的运算,其中包括双波浪号和双感叹号的运算,文中给出了详细的示例代码,需要的朋友们可以参考借鉴,狼蚁网站SEO优化来一起看看吧。
一、双波浪号
var i = 5.1; var j = 5.5; console.log(~~i); // 5 console.log(~~j); // 5
作用类似Math.floor
。
类似的意思是在处理正数的时候,如果处理负数就它俩就不同了:
~~-5.1 // 5 Math.floor(-5.1) // -6 ~~-5.5 // 5 Math.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. ~~ 是向0计算,取值向0靠拢
二、双感叹号
var a = 1; var b = null; var c = ''; var d = 'code'; console.log(!!a); // true console.log(!!b); // false console.log(!!c); // false console.log(!!d); // true
作用类似Boolean,把值转换为boolean值。
总结
以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对狼蚁SEO的支持。
上一篇:Node.js调试技术总结分享
下一篇:利用Node.js对文件进行重命名
编程语言
- 机械手焊接机器人编程 机械手焊接设备编程
- vb数据库编程实例,vb做数据库
- tiobe世界编程语言排行榜,全球编程语言排行
- 成都java编程培训 成都it编程培训中心
- 编程基础培训,编程基础知识培训
- flash游戏编程基础教程,flash游戏开发教程
- 不会英语能学编程吗 不会英语可以学程序员吗
- 爱心代码编程C语言 爱心代码编程c语言公式
- c语言编程学习入门 c语言编程快速入门
- 西门子plc编程培训 西门子plc编程培训班
- 哪里可以学编程 台州哪里可以学编程
- 少儿编程哪个好 少儿编程哪个品牌好
- 编程是什么意思,图形编程是什么意思
- c语言编程软件下载,c语言编程软件在哪下载
- java编程软件下载,java编程下载手机版
- ug编程培训学校,ug编程培训教程