Get the App
SLTechnology News&Howtos  ›  Development  › 

Operation example of js integers

Shulou Source: shulou.com Published: 2022-06-01 05:41:50 09月28日 Update

This article shares with you an example of how to manipulate js integers. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Operation of js integers

Using | 0 and ~ ~ can convert floating point to integer and is faster than similar parseInt,Math.round in terms of efficiency, which is useful when dealing with effects such as pixel and animation displacement. For performance comparison, see here.

Var foo = (12.4 / 4.13) | 0 governance / result is 3var bar = ~ (12.4 / 4.13); / / result is 3

There is another trick, that is! 2 exclamation marks, you can say a value, quickly converted to a Boolean value. You can test it!

Var eee= "eee"; alert (!! eee)

True is returned, which means that any value is preceded by!! Can always be equal to true. Unless this value is already a Boolean, or undefined, null, 0, false, NaN,'', because I mentioned undefined, null, 0, false, NaN,'', these are already false, so I added two!! After that, it's still fasle.

Thank you for reading! On the "js integer operation examples" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Tags: Integers that is examples content Boolean more articles results good practical two that is pixels animation exclamation marks similar performance skills effects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL MariaDB Microsoft vpn Xiaomi