3. What Are Math?
The math object provides you properties and methods for mathematical
constants and functions.
Unlike other global objects, Math is not a constructor.
All the properties and methods of Math are static and can be called by
using Math as an object without creating it.
Thus, you refer to the constant pi as Math.PI and you call the sine function as
Math.sin(x),
where x is the method's argument.
Syntax
The syntax to call the properties and methods of Math are as follows:
var pi_val = Math.PI;
var sine_val = Math.sin(30);
4. Math Properties
1. Math-E
This is an Euler's constant and the base of natural logarithms,
approximately 2.718.
Example:
<script type="text/javascript">
var property_value = Math.E //Syntax: Math.E
document.write("Property Value is :" + property_value);
</script>
Output :
Property Value is :2.718281828459045
5. 2 ) Math-LN2
It returns the natural logarithm of 2 which is approximately 0.693.
Example:
<script type="text/javascript">
var property_value = Math.LN2
document.write("Property Value is : " + property_value);
</script>
Output
Property Value is : 0.6931471805599453
6. 3 ) Math-LN10
It returns the natural logarithm of 10 which is approximately 2.302.
Example:
<script type="text/javascript">
var property_value = Math.LN10 //Syntax: Math.LN10
document.write("Property Value is : " + property_value);
</script>
Output
Property Value is : 2.302585092994046
7. 4 ) Math-LOG2E
It returns the base 2 logarithm of E which is approximately 1.442.
Example:
<script type="text/javascript">
var property_value = Math.LOG2E //Syntax: Math.LOG2E
document.write("Property Value is : " + property_value);
</script>
Output
Property Value is : 1.4426950408889634
8. 5 ) Math-LOG10E
It returns the base 2 logarithm of E which is approximately 0.434..
Example:
<script type="text/javascript">
var property_value = Math.LOG10E //Syntax: Math.LOG10E
document.write("Property Value is : " + property_value);
</script>
Output
Property Value is : 0.4342944819032518
9. 6 ) Math-PI
It returns the ratio of the circumference of a circle to its diameter which
is approximately 3.14159.
Example:
<script type="text/javascript">
var property_value = Math.PI //Syntax: Math.PI
document.write("Property Value is : " + property_value);
</script>
Output
Property Value is : 3.141592653589793
10. 7 ) Math-SQRT1_2
It returns the square root of 1/2; equivalently, 1 over the square
root of 2 which is approximately 0.707.
Example:
<script type="text/javascript">
var property_value = Math.SQRT1_2 //Syntax: Math.SQRT1_2
document.write("Property Value is : " + property_value);
</script>
Output
Property Value is : 0.7071067811865476
11. 8 ) Math-SQRT2
It returns the base 2 logarithm of E which is approximately 1.442.
Example:
<script type="text/javascript">
var property_value = Math.SQRT2 //Syntax: Math.SQRT2
document.write("Property Value is : " + property_value);
</script>
Output
Property Value is : 1.4142135623730951
13. Method Syntax Returns
Math.abs() Absolute value of val.
Math.acos(val) Arc csine (in radians) of val.
Math.asin(val) Arc sine(in radians) of val.
Math.atan(val) Arc Tangent(in radians) of val.
Math.atan2(val1,val2) Angle of polar co-ordinates x and y.
Math.ceil(val) Next integer greater than or equal to
val
Math.cos(val) Cosine of val
Math.exp(val) Eulers constant to the power of val
Math.floor(val) Next integer less than or equal to val
14. Method Syntax Return
Math.log(val) Natural Logarithm (base e) of val
Math.max(val1,val2) The greater of val1 or val2.
Math.min(val1,val2) The lesser of val1 or val2.
Math.pow(val1,val2) Val1 to the val2 power.
Math.random() Random Number between 0 and 1
Math.round(val) N+1 when val>=n.5;otherwise N
Math.sin(val) Sine(in radians) of val
Math.sqrt(val) Square root of val
Math.tan(val) Tangent (in radians) of val
15. 1. sin ( )
This method returns the sine/cosine of a number. The sin method returns a
numeric value between -1 and 1, which represents the sine of the
argument.
Syntax
Its syntax is as follows:
Math.sin ( x );
2. cos ( )
This method returns the cosine of a number. The cos method returns a
numeric value between -1 and 1, which represents the cosine of the angle.
Syntax
Its syntax is as follows:
Math.cos ( x );
16. Example of sin() & cos():
<script type="text/javascript">
var value = Math.sin(0.5);
document.write("First Test Value : " + value );
var value = Math.sin(90);
document.write("<br />Second Test Value : " + value );
var value = Math.sin(Math.PI/2);
document.write("<br />Third Test Value : " + value );
var value = Math.cos(30);
document.write("<br />Fourth Test Value : " + value );
var value = Math.cos(-1);
document.write("<br />Fifth Test Value : " + value );
var value = Math.cos(2*Math.PI);
document.write("<br />sixth Test Value : " + value );
</script>
OUTPUT:
First Test Value : 0.479425538604203
Second Test Value : 0.8939966636005579
Third Test Value : 1
Fourth Test Value : 0.15425144988758405
Fifth Test Value : 0.5403023058681398
Sixth Test Value : 1
17. 3. abs ():
This method returns the absolute value of a number.
4. acos ():
This method returns the arc cosine in radians of a number. The
acos method returns a numeric value between 0 and pi radians for x between -1
and 1. If the value of number is outside this range, it returns NaN.
5. asin ( )
This method returns the arc sine in radians of a number.
The asin method returns a numeric value between -pi/2 and pi/2
radians for x between -1 and 1. If the value of number is outside this
range, it returns NaN.
6. atan ( )
This method returns the arc tangent in radians of a
number. The atan method returns a numeric value between -pi/2 and pi/2
radians.
18. Example of Abs(),sin(),cos(),tan():
<script type="text/javascript">
var value = Math.abs(-1); //syntax [Math.abs(x)]
document.write("First Test Value : " + value );
var value = Math.acos(-1); //syntax [Math.acos(x)]
document.write("<br />Second Test Value : " + value );
var value = Math.asin(null); //syntax [Math.asin(x)]
document.write("<br />Third Test Value : " + value );
var value = Math.atan(2); //syntax [Math.atan(x)]
document.write("<br />Fourth Test Value : " + value );
</script>
Output:
First Test Value : 1
Second Test Value : 3.141592653589793
Third Test Value : 0
Fourth Test Value : 1.1071487177940904
19. 7. atan2 ( ):
This method returns the arctangent of the quotient of its arguments.
The atan2 method returns a numeric value between -pi and pi representing the
angle theta of an (x, y) point.
Return Value
Returns the arctangent in radians of a number.
Math.atan2 ( ±0, -0 ) returns ±PI.
Math.atan2 ( ±0, +0 ) returns ±0.
Math.atan2 ( ±0, -x ) returns ±PI for x < 0.
Math.atan2 ( ±0, x ) returns ±0 for x > 0.
Math.atan2 ( y, ±0 ) returns -PI/2 for y > 0.
Math.atan2 ( ±y, -Infinity ) returns ±PI for finite y > 0.
Math.atan2 ( ±y, +Infinity ) returns ±0 for finite y > 0.
Math.atan2 ( ±Infinity, +x ) returns ±PI/2 for finite x.
Math.atan2 ( ±Infinity, -Infinity ) returns ±3*PI/4.
Math.atan2 ( ±Infinity, +Infinity ) returns ±PI/4.
20. Example
<script type="text/javascript">
var value = Math.atan2(90,15); //syntax Math.atan2 ( x, y ) ;
document.write("First Test Value : " + value );
var value = Math.atan2(15,90);
document.write("<br />Second Test Value : " + value );
var value = Math.atan2(0, -0);
document.write("<br />Third Test Value : " + value );
var value = Math.atan2(+Infinity, -Infinity);
document.write("<br />Fourth Test Value : " + value );
</script>
Output
First Test Value : 1.4056476493802699
Second Test Value : 0.16514867741462683
Third Test Value : 3.141592653589793
Fourth Test Value : 2.356194490192345
21. 8. random ( ):
This method returns a random number between 0 (inclusive) and 1
(exclusive).
Example:
<script type="text/javascript">
var value = Math.random( ); //syntax
document.write("First Test Value : " + value );
var value = Math.random( );
document.write("<br />Second Test Value : " + value );
var value = Math.random( );
document.write("<br />Third Test Value : " + value );
var value = Math.random( );
document.write("<br />Fourth Test Value : " + value );
</script>
OUTPUT:
First Test Value : 0.6063521587330739
Second Test Value : 0.014614846568138051
Third Test Value : 0.020051609523511704
Fourth Test Value : 0.9489513325842974
22. 9. round ( ):
This method returns the value of a number rounded to the nearest
integer.
Example:
<script type="text/javascript">
var value = Math.round( 0.5 );
document.write("First Test Value : " + value );
var value = Math.round( 49.7 );
document.write("<br />Second Test Value : " + value );
var value = Math.round( 50.3 );
document.write("<br />Third Test Value : " + value );
var value = Math.round( -50.3 );
document.write("<br />Fourth Test Value : " + value );
</script>
OUTPUT:
First Test Value : 1
Second Test Value : 50
Third Test Value : 50
Fourth Test Value : -50
23. 10. min ( ) & max():
This method returns the smallest of zero or more numbers. If no arguments
are given, the results is +Infinity/ –Infinity.
Example:
<script type="text/javascript">
var value = Math.min(-1, -3, -40); //syntax:Math.min (value1, value2, ... valueN ) ;
document.write("<br />First Test Value : " + value );
var value = Math.min(0, -1);
document.write("<br/>Second Test Value : " + value );
var value = Math.max(10, 20, -1, 100); ); //syntax:Math.min (value1, value2, ... valueN ) ;
document.write("<br />Third Test Value : " + value );
var value = Math.max(-1, -3, -40);
document.write("<br />Fourth Test Value : " + value );
</script>
OUTPUT:
First Test Value : -40
Second Test Value : -1
Third Test Value : 100
Fourth Test Value : -1
24. 11.floor ( )
This method returns the largest integer less than or
equal to a number.
Example:
<script type="text/javascript">
var value = Math.floor(10.3);
document.write("First Test Value : " + value );
var value = Math.floor(30.9);
document.write("<br />Second Test Value : " + value );
var value = Math.floor(-2.9);
document.write("<br />Third Test Value : " + value );
var value = Math.floor(-2.2);
document.write("<br />Fourth Test Value : " + value );
</script>
OUTPUT:
First Test Value : 10
Second Test Value : 30
Third Test Value : -3
Fourth Test Value : -3
25. 12.ceil ( )
This method returns the smallest integer greater than
or equal to a number.
Example:
<script type="text/javascript">
var value = Math.ceil(20.95);
document.write("First Test Value : " + value );
var value = Math.ceil(20.20);
document.write("<br />Second Test Value : " + value );
var value = Math.ceil(-20.95);
document.write("<br />Third Test Value : " + value );
var value = Math.ceil(-20.20);
document.write("<br />Fourth Test Value : " + value );
</script>
Output:
First Test Value : 21
Second Test Value : 21
Third Test Value : -20
Fourth Test Value : -20
26. 13.sqrt ( )
This method returns the square root of a number. If the value of a
number is negative, sqrt returns NaN.Example:
<script type="text/javascript">
var value = Math.sqrt( 2.5 );
document.write("First Test Value : " + value );
var value = Math.sqrt( 256 );
document.write("<br />Second Test Value : " + value );
var value = Math.sqrt( 23 );
document.write("<br />Third Test Value : " + value );
var value = Math.sqrt( -9 );
document.write("<br />Fourth Test Value : " + value );
</script>
Output:
First Test Value : 1.5811388300841898
Second Test Value : 16
Third Test Value : 4.795831523312719
Fourth Test Value : NaN
28. What is Boolean?
The Boolean object represents two values, either "true" or
"false".
If value parameter is omitted or is 0, -0, null, false, NaN,
undefined, or the empty string (""), the object has an
initial value of false.
You’ve already seen dozen of instances where
programs make all kind of decisions based on whether a
statement or expression is Boolean value true or false.
With just two values-true and false you can assemble a
string of expressions that yield Boolean results then
Boolean arithmetic figure out whether the bottom line is
true or false.
29. Boolean operators :
Syntax Name Operands Results
&& And Boolean Boolean
|| Or Boolean Boolean
! Not One Boolean Boolean
30. AND OPERATOR
The and (&&) operator joins two Boolean values to reach a true or false value
based on the result of both value.
5>1 && 50>10 //result=true.
5>1 && 50<10 //result=false.
Left operand And Operand Right Operand Result
True && True True
True && False False
False && True False
False && False False
31. Or operator:
If one or other (or both) operands is true, the operation returns true.
5>1 || 50>10 //result = true
5>1 || 50<10 //result = true
Left Operand Or Operator Right Operator Result
True || True True
True || False True
False || False True
False || False False
32. Not operators:
The not operators precedes any Boolean value to switch it back to the
opposite value (from true to false, or from false to true).
!(10>5) //result=false
!true //result=false
Left operand Not operator Result
True ! False
False ! True
33. Boolean uses:
Comparisons and Conditions
Booleans are used in comparisions like <,>,<=,>=,==.
Booleans can be used in conditional statements like if,
while etc.
Operator Description Example
== equal to if (day == "Monday")
> greater than if (salary > 9000)
< less than if (age < 18)
34. Example:
<!DOCTYPE html>
<html>
<body>
<p>Assign 5 to x, and display the value of the
comparisons (x == 8, x > 8, x < 8).</p>
<button onclick="myFunction()">Try it</button>
<h1 id="demo"></h1>
<h1 id="demo1"></h1>
<h1 id="demo2"></h1>
35. <script>
function myFunction()
{
var x = 5;
document.getElementById("demo").innerHTML = (x == 8);
document.getElementById("demo1").innerHTML = (x > 8);
document.getElementById("demo2").innerHTML = (x < 8);
}
</script>
</body>
</html>
Assign 5 to x, and display the value of the comparison (x > 8).
36. Boolean Methods:
Method Description
toSource() Returns a string containing the source of the Boolean object;
you can use this string to create an equivalent object.
toString() Returns a string of either "true" or "false" depending upon the
value of the object.
valueOf() Returns the primitive value of the Boolean object.
37. toSource () :
toSource() method returns a string
representing the source code of the object.
Syntax:- Its syntax is as follows:
boolean.toSource()
Return Value:-
Returns a string representing the source code
of the object.
38. Example:
<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() is : "+
newBook.toSource());
</script>
Output :-
({title:"Perl", publisher:"Leo Inc", price:200})
39. toString ()
This method returns a string of either "true" or "false" depending
upon the value of the object.
Syntax :-
boolean.toString()
Return Value:-
Returns a string representing the specified Boolean object.
Example:
<script type="text/javascript">
var flag = new Boolean(false);
document.write( "flag.toString is : " + flag.toString() );
</script>
Output
flag.toString is : false
40. valueOf ():
Javascript boolean valueOf() method returns the primitive value of the
specified boolean object.
Syntax:-
boolean.valueOf()
Example:
<script type="text/javascript">
var flag = new Boolean(false);
document.write( "flag.valueOf is : " + flag.valueOf() );
</script>
Output :-
flag.valueOf is : false
42. STRINGS
Series of letters.
Example :-
“Javascript”
'http://www.quirksmode.org’
‘14’
Javascript wraps string primitive datatype with number of helper
methods.
Zero based index system.
Javascript treats primitive types as objects, when dealing with
methods and properties.
43. STRINGS CREATION
Single quotes or Double quotes compulsory
Syntax
var str = new String (string); // string is encoded parameter
var name = ‘string’;
Example
var str = new String(‘Javascript’);
var name = ‘Lalit’
44. String Length
Property :- length
Example :-
<p id="demo"></p>
<script>
var txt = “Lalit Aphale";
document.getElementById("demo").innerHTML = txt.length;
</script>
Output :-
12
*It also calculates the space.
45. Break long line code :-
Two types :-
Backslash ()
String Addition.
Example :-
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Good
Afternoon.";
</script>
Output :-
Good Afternoon.
46. Break long line code :-
Example :-
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Good " +
"Afternoon.";
</script>
Output :-
Good Afternoon
47. String As Object
The primitive datatype String can be used as object also.
Normal syntax :-
var a = “FYMCA";
As Object :-
var b = new String(“FYMCA");
Example :-
<p id="demo"></p>
<script>
var a = "FYMCA";
var b = new String("FYMCA");
document.getElementById("demo").innerHTML =
typeof a + "<br>" + typeof b;
</script>
Output :-
string
object
48. Equality Operators
There are two types of equality operators :-
Returns Boolean value.
If Strings are same
== (e.g : a==b)
If String types are same
=== (e.g : a===b)
Example :-
<p id="demo"></p>
<script>
var a = "FYMCA";
var b = new String("FYMCA");
document.getElementById("demo").innerHTML = (a==b);
</script>
Output:-
true
49. Equality Operators
Example :-
<p id="demo"></p>
<script>
var a = "FYMCA";
var b = new String("FYMCA");
document.getElementById("demo").innerHTML = (a===b);
</script>
Output :-
false
50. String html wrappers
A copy of string wrapped in appropriate HTML tag.
big() :- Displays text in big font size.
Example :-
<p id="demo"></p>
<script>
function myFunction() {
var str = "FYMCA!";
var result = str.big();
document.getElementById("demo").innerHTML = result;
}
</script>
Output :-
FYMCA!
51. String html wrappers
small() :- Displays text in small font size.
Example :-
<p id="demo"></p>
<script>
function myFunction() {
var str = "FYMCA!";
var result = str.small();
document.getElementById("demo").innerHTML = result;
}
</script>
Output :-
FYMCA!
52. String html wrappers
fontcolor() :- Displays text in specified font color.
Example :-
<p id="demo"></p>
<script>
function myFunction() {
var str = "FYMCA!";
var result = str.fontcolor(“red”);
document.getElementById("demo").innerHTML = result;
}
</script>
Output :-
FYMCA!
53. Some More….
Method Description
bold() Displays text in bold font style
italics() Displays text in italics font style
fontsize() Displays text in specified font size
link() Directs to the specified URL
strike() Displays Struke-out text
54. String properties
Primitive values cant have properties and methods.
BUT, IN JAVASCRIPT
Primitive values are treated as objects when dealing with properties
and methods.
Property Description
Constructor Returns the function that created
the string object’s prototype.
Length Returns length of string.
Prototype Adds properties and methods to
object.
55. Prototype :-
<script>
function stud(name, roll, born)
{
this.name=name;
this.roll=roll;
this.born=born;
}
stud.prototype.mark = 90;
var abc = new stud("Lalit", "2", 1995);
document.write(abc.mark);
</script>
Output :-
90
56. String methods
charAt() :-
Returns the character at specific position.
Syntax :-
strObject.charAt(number) ;
Example :-
<script>
var str = new String( "Good Afternoon" );
document.write("str.charAt(0) is:" + str.charAt(0));
document.write("<br />str.charAt(1) is:" + str.charAt(1));
document.write("<br />str.charAt(2) is:" + str.charAt(2));
document.write("<br />str.charAt(5) is:" + str.charAt(5));
</script>
OUTPUT:
str.charAt(0) is:G
str.charAt(1) is:o
str.charAt(2) is:o
str.charAt(5) is:A
57. indexOf():-
Returns the index of specified string.
Syntax :-
strObject.indexOf(“string”);
Index count starts from 0.
Example:-
<script>
var str1 = new String( "Make the way for MCA" );
var index = str1.indexOf( "way" );
document.write("indexOf found String :" + index );
document.write("<br />");
var index = str1.indexOf( "MCA" );
document.write("indexOf found String :" + index );
</script>
Output:-
indexOf found String :9
indexOf found String :17
58. concat():-
It concatenates two strings and return that string.
Syntax :-
strObject.concat(string1,string2,……string n);
Example :-
<script>
var str1 = new String( "K.J." );
var str2 = new String( "SIMSR" );
var str3 = str1.concat( str2 );
document.write("Concatenated String :" + str3);
</script>
Output :-
Concatenated String :K.J.SIMSR
59. Search() :-
This method is used for searching specific string in another string.
Syntax :-
strObject.search(“string”);
Returns index of specified string, otherwise returns -1.
Example :-
<script>
var str = "Lalit Aphale!";
var n = str.search("Aphale");
document.write(n);
</script>
Output :-
6
60. toLowerCase():-
It returns the string in lower case format.
Syntax :-
strObject.toLowerCase();
Example :-
<script>
var str = "K.J.SIMSR";
document.write(str.toLowerCase( ));
</script>
Output :-
k.j.simsr
61. Some more methods….
Syntax Description
charCodeAt(index) Returns the Unicode value of
character at specified index.
replace(string variable,”string”) Replaces a string with specified string.
slice(beginslice,endslice) Slices the string according to specified
size.
lastIndexOf(“string”) Retruns the position of last location of
specified string.
substr(start,length) Returns the characters from specified
start position to the specified length.
substring(index A,index B) It returns the subset of the string.
63. Date Properties:
Property Description
constructor Specifies the function that creates
an object's prototype.
prototype The prototype property allows you
to add properties and methods to
an object.
64. constructor
Javascript date constructor property returns a reference to the array
function that created the instance's prototype.
Syntax:
Its syntax is as follows:
date.constructor
Return Value:
Returns the function that created this object's instance.
Example:
<script type="text/javascript">
var dt = new Date();
document.write("dt.constructor is : " + dt.constructor);
</script>
OUTPUT:
dt.constructor is : function Date() { [native code] }
65. Prototype:
The prototype property allows you to add properties
and methods to any object (Number, Boolean, String,
Date, etc.).
Note:
Prototype is a global property which is available with
almost all the objects.
Syntax:
Its syntax is as follows:
object.prototype.name = value
66. EXAMPLE:
<html>
<head>
<script type="text/javascript">
function book(title, author)
{
this.title = title;
this.author = author;
}
</script>
</head>
<body>
<script type="text/javascript">
var myBook = new book("JAVA", "Sameer");
book.prototype.price=1000;
//myBook.price = 1000;
document.write("Book title is : " + myBook.title + "<br>");
document.write("Book author is : " + myBook.author + "<br>");
document.write("Book price is : " + myBook.price + "<br>");
</script>
</body>
OUTPUT:
Book title is : JAVA
Book author is : Sameer
Book price is : 1000
68. Method Value Range Description
dateObj.getDate()
Dateobj.setDate()
1-31 Date within the month
dateObj. getDay()
dateObj. setDay()
0-6 Day of the Week
dateObj. getFullYear()
dateObj. setFullYear()
1970-… Get the four digit year
(yyyy).
Set the year
dateObj. getHours()
dateObj. setHours()
0-23 Hour of the day in 24-
Hour time
dateObj. getMilliseconds()
dateObj. setMilliseconds()
0-999 Milliseconds since the
previous full
second(NN4+,Mozl+,Ie3+)
69. Method Value Range Description
dateObj. getMonth()
dateObj. setMonth()
0-11 Month within the
year(January=0)
dateObj.getSeconds() 0-59 Second within the
specified minute
dateObj. getMinutes()
dateObj. setMinutes()
0-59 Minute of the specified
Hour
dateObj.getTime() 0-… Milliseconds since 1/1/70
00:00:00 GMT
71. setTime ()
Javascript date setTime() method sets the Date object to the
time represented by a number of milliseconds since January 1, 1970,
00:00:00 UTC
Example:
<script type="text/javascript">
var dt = new Date( "Aug 28, 2008 23:30:00" );
dt.setTime( 5000000 );
document.write( dt );
</script>
OUTPUT:
Thu Jan 01 1970 06:53:20 GMT+0530 (India Standard Time)
Syntax:
Date.setTime(timeValue)
72. Example:
<script type="text/javascript">
var d = new Date( "Aug 21, 2008 12:30:00" );
d.setFullYear( 2015 );
document.write( d );
</script>
Set Full Year.
OUTPUT:
Fri Aug 21 2015 12:30:00 GMT+0530 (India Standard Time)
Javascript date setFullYear() method sets the full year for a
specified date according to local time.
Syntax:
Date.setFullYear(yearValue[, monthValue[, dayValue]])
73. Display Current Hours ,Minutes & seconds.
EXAMPLE:
<script type="text/javascript">
var d = new Date();
document.write(d.getHours()+":"+d.getMinutes()+":"+d.getSeconds())
</script>
Output:
13:2:5
74. Display Current Date & Day Of The Week
Example:
<script type="text/javascript">
var d = new Date();
document.write("Today's Date is "+ d.getDate() + "/" + (d.getMonth()+1)
+"/"+ d.getFullYear() +"<br>"+ "Today is" +" : "+ d.getDay() + " Day of the
weak") ;
</script> OUTPUT:
Today's Date is 3/10/2015.
Today is 6 Day of the weak.
75. • toDateString ():
Javascript date toDateString() method returns the date portion
of a Date object in human readable form.
Example:
<script type="text/javascript">
var dt = new Date(1993, 6, 28, 14, 39, 7);
document.write( "Formated Date : " + dt.toDateString() );
document.write( "<br>Formated Date : " + dt.toUTCString() );
</script>
• toUTCString():
This method converts a date to a string, using the universal time convention.
Syntax:
Date.toDateString()
Date.toUTCString()
OUTPUT:
Formated Date : Wed Jul 28 1993
Formated Date : Wed, 28 Jul 1993 09:09:07 GMT