js_tutorial

Javascript constructor

Javascript constructor It returns a reference to the Number function that created the instance's prototype. Syntax Its syntax is as follows: number.constructor() Return value Returns the function that created this object's instance. Example Try the following example. JavaScript constructor() Method var num = new Number( 177.1234 ); document.write("num.constructor() is : " + num.constructor); Output num.constructor() is : function Number() { [native code] } Number Methods The Number object contains only the default methods that are a part of every object's definition. Method Description toExponential() Forces a number to display in exponential notation, even if 120

Javascript the number is in the range in which JavaScript normally uses standard notation. toFixed() Formats a number with a specific number of digits to the right of the decimal. toLocaleString() Returns a string value version of the current number in a format that may vary according to a browser's local settings. toPrecision() toString() valueOf() Defines how many total digits (including digits to the left and right of the decimal) to display of a number. Returns the string representation of the number's value. Returns the number's value. In the following sections, we will have a few examples to explain the methods of Number. toExponential () This method returns a string representing the number object in exponential notation. Syntax Its syntax is as follows: number.toExponential( [fractionDigits] ) Parameter Details fractionDigits: An integer specifying the number of digits after the decimal point. Defaults to as many digits as necessary to specify the number. Return Value A string representing a Number object in exponential notation with one digit before the decimal point, rounded to fractionDigits digits after the decimal point. If the fractionDigits argument is omitted, the number of digits after the decimal point defaults to the number of digits necessary to represent the value uniquely. Example 121