Pages

Javascript Boolean valueOf() Method

4/4/14

Description:

Javascript boolean valueOf() method returns the primitive value of the specified booleanobject..

Syntax:

boolean.valueOf()
Here is the detail of parameters:
  • NA

Return Value:

Returns the primitive value of the specified boolean object.

Example:

<html>
<head>
<title>JavaScript valueOf() Method</title>
</head>
<body>
<script type="text/javascript">
var flag = new Boolean(false); 
document.write( "flag.valueOf is : " + flag.valueOf() ); 
</script>
</body>
</html>
This will produce following result:
flag.valueOf is : false 
Read more ...

Javascript Boolean toString() Method

4/4/14

Description:

This method returns a string of either "true" or "false" depending upon the value of the object.

Syntax:

boolean.toString()
Here is the detail of parameters:
  • NA

Return Value:

Returns a string representing the specified Boolean object.

Example:

<html>
<head>
<title>JavaScript toString() Method</title>
</head>
<body>
<script type="text/javascript">
var flag = new Boolean(false); 
document.write( "flag.toString is : " + flag.toString() ); 
</script>
</body>
</html>
This will produce following result:
flag.toString is : false 
Read more ...

Javascript Boolean toSource() Method

4/4/14

Description:

Javascript boolean toSource() method returns a string representing the source code of the object.
Note: This method does not work in Internet Explorer.

Syntax:

boolean.toSource()
Here is the detail of parameters:
  • NA

Return Value:

Returns a string representing the source code of the object.

Example:

<html>
<head>
<title>JavaScript toSource() Method</title>
</head>
<body>
<script type="text/javascript">
function book(title, publisher, price)
{
   this.title = title;
   this.publisher = publisher;
   this.price = price;
}
var newBook = new book("Perl","Leo Inc",200); 
document.write(newBook.toSource()); 
</script>
</body>
</html>
This will produce following result:
({title:"Perl", publisher:"Leo Inc", price:200})
Read more ...

Javascript Number - valueOf()

4/4/14

Description:

This method returns the primitive value of the specified number object.

Syntax:

number.valueOf()
Here is the detail of parameters:
  • NA

Return Value:

Returns the primitive value of the specified number object.

Example:

<html>
<head>
<title>JavaScript valueOf() Method </title>
</head>
<body>
<script type="text/javascript">
   var num = new Number(15.11234);
   document.write("num.valueOf() is " + num.valueOf());
</script>
</body>
</html>
This will produce following result:
num.valueOf() is 15.11234 
Read more ...

Javascript Number - toString()

4/4/14

Description:

This method returns a string representing the specified object. The toString method parses its first argument, and attempts to return a string representation in the specified radix (base).

Syntax:

number.toString( [radix] )
Here is the detail of parameters:
  • radix: An integer between 2 and 36 specifying the base to use for representing numeric values.

Return Value:

Returns a string representing the specified Number object.

Example:

<html>
<head>
<title>JavaScript toString() Method </title>
</head>
<body>
<script type="text/javascript">
   var num = new Number(15);
   document.write("num.toString() is " + num.toString());
   document.write("<br />"); 

   document.write("num.toString(2) is " + num.toString(2)); 
   document.write("<br />"); 

   document.write("num.toString(4) is " + num.toString(4)); 
   document.write("<br />"); 
</script>
</body>
</html>
This will produce following result:
num.toString() is 15
num.toString(2) is 1111
num.toString(4) is 33
Read more ...

Javascript Number - toPrecision()

4/4/14

Description:

This method returns a string representing the number object to the specified precision.

Syntax:

number.toPrecision( [ precision ] )
Here is the detail of parameters:
  • precision: An integer specifying the number of significant digits.

Return Value:

Returns a string representing a Number object in fixed-point or exponential notation rounded toprecision significant digits.

Example:

<html>
<head>
<title>JavaScript toPrecision() Method </title>
</head>
<body>
<script type="text/javascript">
   var num = new Number(7.123456);
   document.write("num.toPrecision() is " + num.toPrecision());
   document.write("<br />"); 

   document.write("num.toPrecision(4) is " + num.toPrecision(4)); 
   document.write("<br />"); 

   document.write("num.toPrecision(2) is " + num.toPrecision(2)); 
   document.write("<br />"); 

   document.write("num.toPrecision(1) is " + num.toPrecision(1)); 
</script>
</body>
</html>
This will produce following result:
num.toPrecision() is 7.123456
num.toPrecision(4) is 7.123
num.toPrecision(2) is 7.1
num.toPrecision(1) is 7 
Read more ...

Javascript Number - toLocaleString()

4/4/14

Description:

This method converts a number object, into a human readable string representing the number using the locale of the environment.

Syntax:

number.toLocaleString()
Here is the detail of parameters:
  • NA:

Return Value:

Returns a human readable string representing the number using the locale of the environment.

Example:

<html>
<head>
<title>JavaScript toLocaleString() Method </title>
</head>
<body>
<script type="text/javascript">
   var num = new Number(177.1234);
   document.write( num.toLocaleString()); 
</script>
</body>
</html>
This will produce following result:
177.1234
Read more ...

Javascript Number - toFixed()

4/4/14

Description:

This method formats a number with a specific number of digits to the right of the decimal.

Syntax:

number.toFixed( [digits] )
Here is the detail of parameters:
  • digits: The number of digits to appear after the decimal point.

Return Value:

A string representation of number that does not use exponential notation and has exactly digitsdigits after the decimal place.

Example:

<html>
<head>
<title>JavaScript toFixed() Method</title>
</head>
<body>
<script type="text/javascript">
   var num=177.1234;
   document.write("num.toFixed() is : " + num.toFixed()); 
   document.write("<br />"); 
   document.write("num.toFixed(6) is : " + num.toFixed(6)); 
   document.write("<br />"); 
   document.write("num.toFixed(1) is : " + num.toFixed(1)); 
   document.write("<br />"); 

   document.write("(1.23e+20).toFixed(2) is:" + 
                                    (1.23e+20).toFixed(2)); 
   document.write("<br />"); 
   document.write("(1.23e-10).toFixed(2) is : " + 
                                    (1.23e-10).toFixed(2)); 
</script>
</body>
</html>
This will produce following result:
num.toFixed() is : 177
num.toFixed(6) is : 177.123400
num.toFixed(1) is : 177.1
(1.23e+20).toFixed(2) is:123000000000000000000.00
(1.23e-10).toFixed(2) is : 0.00 
Read more ...

Javascript Number - toExponential()

4/4/14

Description:

This method returns a string representing the number object in exponential notation

Syntax:

number.toExponential( [fractionDigits] )
Here is the detail of parameters:
  • 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:

<html>
<head>
<title>Javascript Method toExponential()</title>
</head>
<body>
<script type="text/javascript">
   var num=77.1234;
   var val = num.toExponential(); 
   document.write("num.toExponential() is : " + val ); 
   document.write("<br />"); 

   val = num.toExponential(4); 
   document.write("num.toExponential(4) is : " + val ); 
   document.write("<br />"); 

   val = num.toExponential(2); 
   document.write("num.toExponential(2) is : " + val); 
   document.write("<br />"); 

   val = 77.1234.toExponential(); 
   document.write("77.1234.toExponential()is : " + val ); 
   document.write("<br />"); 

   val = 77.1234.toExponential(); 
   document.write("77 .toExponential() is : " + val); 
</script>
</body>
</html>
This will produce following result:
num.toExponential() is : 7.71234e+1
num.toExponential(4) is : 7.7123e+1
num.toExponential(2) is : 7.71e+1
77.1234.toExponential()is:7.71234e+1
77 .toExponential() is : 7.71234e+1
Read more ...

Javascript Number - constructor()

4/4/14

Description:

This method returns a reference to the Number function that created the instance's prototype.

Syntax:

number.constructor()
Here is the detail of parameters:
  • NA

Return Value:

Returns the function that created this object's instance.

Example:

<html>
<head>
<title>JavaScript constructor() Method</title>
</head>
<body>
<script type="text/javascript">
   var num = new Number( 177.1234 );
   document.write("num.constructor() is : " + num.constructor); 
</script>
</body>
</html>
This will produce following result:
num.constructor() is : function Number() { [native code] }
Read more ...

Related Posts