Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does es6 tell if it's a number?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "how to judge whether es6 is a number or not". The editor shows you the operation process through an actual case. The operation method is simple and fast, and it is practical. I hope this article "how to judge whether es6 is a number or not" can help you solve the problem.

In es6, you can use the isFinite () method of the Number object to determine whether the value is a number, which can detect whether the passed parameter value is a finite number; the syntax "Number.isFinite".

The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.

ES6 provides us with a way to judge numbers, as shown in the following code

Number.isFinite judgment number

The Number.isFinite () method is used to detect whether the parameter passed in is a finite number.

Let a = 1console.log (Number.isFinite (a)); / / trueconsole.log (Number.isFinite ("beline")); / / falseconsole.log (Number.isFinite (NaN)); / / falseconsole.log (Number.isFinite (undefined)); / / false

Number.isNaN judge non-numeric

Console.log (Number.isNaN (NaN)); / / trueconsole.log (Number.isNaN (1)); / / false

Number.isInteger determines whether it is an integer or not

Let a = 66console.log (Number.isInteger (a)); / / true

If you need to judge whether it is floating-point or not, you only need to add a reverse symbol in front of the object.

Let a = 111.77console.log (! Number.isInteger (a)); / / true

Safe integer

The range of safe values for computer digital types is 2 to the power of 53.

Let num = Math.pow (2,53)-1 share console.log (num) / / 9007199254740991

Why ES6 provides the constants of the maximum safe integer and the minimum safe integer, and the isSafeInteger method can be used to determine whether the incoming value is within the range of safe integers. In daily work, if we exceed this number, we need to convert the value into a string to show to the user.

Console.log (Number.MAX_SAFE_INTEGER) / / 9007199254740991console.log (Number.MIN_SAFE_INTEGER) / /-9007199254740991ax / determine whether num is within the range of safe integers console.log (Number.isSafeInteger (num)) / / true on "how to determine whether es6 is a number" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report