JavaScript Pow () method
The POW () method returns the value of the Y-power of X
Grammar
Math.pow (x, y)
Parameters |
Description |
X |
Necessary. Base Must be a number. |
Y |
Necessary. The power number. Must be a number. |
return value
The Y power of X.
Description
If the result is an imaginary number or a negative number, the method returns NaN. If a floating-point overflow is caused by an exponent that is too large, the method returns Infinity.
Instance
In the following example, we will apply the POW () to a different number combination:
<script type= "Text/javascript" >document.write (Math.pow (0,0) + "<br/>") document.write (Math.pow (0,1) + " <br/> ") document.write (Math.pow (+) +" <br/> ") document.write (Math.pow (1,10) +" <br/> ") document.write (Math.pow (2,3) + "<br/>") document.write (Math.pow ( -2,3) + "<br/>") document.write (Math.pow (2,4) + "<br/>") document.write (Math.pow ( -2,4) + "<br/>") </script>
Output:
10118-81616
JavaScript parseint () function
JavaScript Global Objects
Definition and usage
The parseint () function parses a string and returns an integer.
Grammar
parseint (stringradix)
Parameters |
Description |
String |
Necessary. The string to be parsed. |
Radix |
Optional. Represents the cardinality of the number to parse. The value is between 2 and 36. If this argument is omitted or its value is 0, the number is parsed based on 10. If it starts with "0x" or "0X", it will have a base of 16. If the parameter is less than 2 or greater than 36, parseint () returns NaN. |
return value
Returns the parsed number.
Description
When the value of the parameter radix is 0, or if the parameter is not set, parseint () determines the cardinality of the number based on string .
For example, if string starts with "0x", parseint () resolves the remainder of the string to a 16-binary integer. If string starts with 0, then ECMAScript V3 allows an implementation of parseint () to parse subsequent characters into octal or hexadecimal digits. If string starts with a number from 1 to 9, parseint () parses it into a decimal integer.
Hints and Notes
Note: Only the first number in a string is returned.
Note: Spaces at the beginning and end are allowed.
Tip: If the first character of a string cannot be converted to a number, parsefloat () returns NaN.
Instance
In this example, we will use parseint () to parse the different strings:
parseint ("10");//returns 10PARSEINT ("19", 10);//returns 10+9 parseint ("11", 2),//returns 3 (2+1) parseint ("17", 8);//returns 15 (8+7) parseint ("1f", 16);//Return to 16+15 parseint ("010");//undecided: return 10 or 8
JavaScript number () function
JavaScript Global Objects
Definition and usage
The number () function converts the value of the object to a digit.
Grammar
Number (object)
Parameters |
Description |
Object |
Necessary. JavaScript object. |
return value
If the parameter is a Date object, number () returns the milliseconds from January 1, 1970 to the present.
The number () function returns NaN if the value of the object cannot be converted to numbers.
Instance
In this example, we will try to convert different objects to numbers:
<script type= "Text/javascript" >var test1= New Boolean (True), Var test2= new Boolean (false), Var test3= new Date (); var test4= new string ("999"), var test5= new String ("999 888");d ocument.write ( Number(test1)
+ "<br/>");d ocument.write ( Number(test2)
+ "<br/>");d ocument.write ( Number(test3)
+ "<br/>");d ocument.write ( Number(test4)
+ "<br/>");d ocument.write ( Number(test5)
+ "<br/>");</script>
Output:
101256657776588999NaN
Common native methods of JS