Number() in How to use Number function is a built-in javascript function used to convert data types to numbers. Let's take a look at the specific use of the Number function.
Let’s first take a look at the basic syntax of the Number function
Number(query javascript variable)
Parameters: The number function is the javascript variable input by the user to be converted. The number function converts any type of javascript variable to numeric type.
The number function returns the number format of any type of javascript variable.
Let’s look at a few specific examples
Example 1:
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> function func() { var value = Number(true); document.write(value); } func(); </script> </body> </html>
The output result is: 1
Example 2:
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> function func() { var a = "10 20"; var value = Number(a); document.write(value); } func(); </script> </body> </html>
The output result is: NaN
Example 3:
The code is as follows
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <script> function func() { var value = Number(new Date("2017-09-30")); document.write(value); } func(); </script> </body> </html>
The output result is: 1506729600000
This article ends here. For more exciting content, you can pay attention to other related column tutorials on the PHP Chinese website! ! !
The above is the detailed content of How to use Number function. For more information, please follow other related articles on the PHP Chinese website!