取出数值的整数部分(取整)。

用位运算来做(右移0位,或者两次取反),且非数值型的值会转成0

alert(5>>0); alert(~~5); // 值为 5
 
alert(5.55>>0); alert(~~5.55); // 值为 5
 
alert(-98.4>>0); alert(~~-98.4); // 值为 -98
 
alert('absd'>>0); alert(~~'absd'); // 值为 0
 
alert(null>>0); alert(~~null); // 值为 0
 
alert('34.5'>>0); alert(~~'34.5'); // 值为 34

  

posted @ 2017-09-12 16:01  neo_o  阅读(802)  评论(0编辑  收藏  举报

愿你的生活只有诗和远方