Professional Documents
Culture Documents
<html>
<head>
</head>
<body>
<script type="text/javascript">
<!--
document.write("Hello World")
//-->
</script>
<p>This is web page body </p>
</body>
</html>
Placement Script in <head> and <body>
<html>
<head>
<script type="text/javascript">
<!--
function sayHello() {
alert("Hello World")
}
//-->
</script>
</head>
<body>
<script type="text/javascript">
<!--
document.write("Hello World")
//-->
</script>
<input type="button" onclick="sayHello()" value="Say Hello" />
</body>
</html>
Placement - Script in an external file and include in <head> section
<html>
<head>
<script type="text/javascript" src="filename.js">
</script>
</head>
<body>
.......
</body>
</html>
filename.js
function sayHello() {
alert("Hello World")
}
JavaScript Datatypes
One of the most fundamental characteristics of a programming language is
the set of data types it supports.
These are the type of values that can be represented and manipulated in a
programming language.
JavaScript allows you to work with three primitive data types:
Numbers, e.g., 123, 120.50 etc.
Strings of text, e.g. "This text string" etc.
Boolean, e.g. true or false.
JavaScript also defines two trivial data types, null and undefined, each of
which defines only a single value.
In addition to these primitive data types, JavaScript supports a composite
data type known as object.
JavaScript Variables
Like many other programming languages, JavaScript has variables.
Variables can be thought of as named containers.
You can place data into these containers and then refer to the data simply by naming the
container.
Before you use a variable in a JavaScript program, you must declare it.
Variables are declared with the var keyword as follows.
var age;
var name;
Storing a value in a variable is called variable initialization.
You can do variable initialization at the time of variable creation or at a later point in time
when you need that variable.
var name = "Ali";
var money;
money = 2000.50;
JavaScript Variables
JavaScript is untyped language. This means that a JavaScript variable
can hold a value of any data type.
Unlike many other languages, you don't have to tell JavaScript during
variable declaration what type of value the variable will hold.
The value type of a variable can change during the execution of a
program and JavaScript takes care of it automatically.
JavaScript Variable Scope
Local JavaScript Variables
Variables declared within a JavaScript function, become LOCAL to the function. Local variables have local scope: They can only be accessed within the function.
Since local variables are only recognized inside their functions, variables with the same name can be used in different functions. Local variables are created when a
function starts, and deleted when the function is completed.
// code here can not use carName
function myFunction() {
var carName = "Volvo";
// code here can use carName
}
Automatically Global
If you assign a value to a variable that has not been declared, it will automatically become a GLOBAL variable.
This code example will declare a global variable carName, even if the value is assigned inside a function.
myFunction();
// code here can use carName
function myFunction() {
carName = "Volvo";
}
JavaScript Variable Names
While naming your variables in JavaScript, keep the following rules in
mind.
You should not use any of the JavaScript reserved keywords as a variable
name. These keywords are mentioned in the next section. For example, break
or boolean variable names are not valid.
JavaScript variable names should not start with a numeral (0-9). They must
begin with a letter or an underscore character. For example, 123test is an
invalid variable name but _123test is a valid one.
JavaScript variable names are case-sensitive. For example, Name and name
are two different variables.
JavaScript Variable Scope
let allows you to declare variables that are limited in scope to the block, statement, or expression
on which it is used.
This is unlike the var keyword, which defines a variable globally, or locally to an entire function
regardless of block scope.
document.write(typeof(length));
document.write(typeof(lastName));
document.write(typeof(x));
With the debugger turned on, this code should stop executing before it executes the third line:
var x = 15 * 5;
debugger;
document.getElementbyId("demo").innerHTML = x;
JavaScript Reserved Words - Delete
The delete operator removes a property from an object.
var Employee = {
age: 28,
name: 'abc',
designation: 'developer'
}
// When trying to delete a property that does not exist, true is returned
console.log(delete Employee.salary); // returns true
When a property is marked as non-configurable, delete won't have any effect, and will return false. In strict mode this will raise a SyntaxError.
// defining constructors
function C() {}
function D() {}
C.prototype = {};
var o2 = new C();
o2 instanceof C; // true
Note: Same logic applies to Bitwise operators, so they will become <<=, >>=,>>=, &=, |= and ^=.
Conditional Statements
JavaScript supports conditional statements which are used to perform
different actions based on different conditions.
Different types of conditional statements supported by JavaScript are
if..else statement.
if...else ifelse statements
Here JavaScript expression is evaluated. If the resulting value is true, the given statement(s) in the if block, are
executed.
If the expression is false, then the given statement(s) in the else block are executed.
The if...else if...else statement is an advanced form of ifelse that allows JavaScript to make a correct decision out of
several conditions.
a switch statement
The objective of a switch statement is to give an expression to evaluate and several different statements to execute
based on the value of the expression.
The interpreter checks each case against the value of the expression until a match is found.
If nothing matches, a default condition will be used.
Conditional Statements
var book = "maths"; var grade='A';
switch (grade)
if( book == "history" ){ {
document.write("<b>History Book</b>"); case 'A': document.write("Good job<br />");
} break;
else if( book == "maths" ){ case 'B': document.write("Pretty good<br />");
document.write("<b>Maths Book</b>"); break;
} case 'C': document.write("Passed<br />");
break;
else if( book == "economics" ){ case 'D': document.write("Not so good<br />");
document.write("<b>Economics Book</b>"); break;
} case 'F': document.write("Failed<br />");
else{ break;
document.write("<b>Unknown Book</b>"); default: document.write("Unknown grade<br />")
} }
Loops
While writing a program, you may encounter a situation where you need to
perform an action over and over again.
In such situations, you would need to write loop statements to reduce the
number of lines.
JavaScript supports all the necessary loops to ease down the pressure of
programming.
JavaScript supports
The while Loop
The do...while Loop
The for Loop
The forin Loop
Loops
var count = 0;
document.write("Starting Loop ");
while (count < 10){
document.write("Current Count : " + count + "<br />");
count++;
}
document.write("Loop stopped!");
var count = 0;
document.write("Starting Loop" + "<br />");
do{
document.write("Current Count : " + count + "<br />");
count++;
}while (count < 5);
document.write ("Loop stopped!");
var aProperty;
var count; document.write("Navigator Object Properties<br /> ");
document.write("Starting Loop" + "<br />"); for (aProperty in navigator)
for(count = 0; count < 10; count++){ {
document.write("Current Count : " + count ); document.write(aProperty);
document.write("<br />"); document.write("<br />");
} }
document.write("Loop stopped!"); document.write
Loop Control
JavaScript provides full control to handle loops and switch
statements.
To handle all such situations, JavaScript provides break and continue
statements.
These statements are used to immediately come out of any loop or to
start the next iteration of any loop respectively.
Loop Control
var x = 1;
document.write("Entering the loop<br /> ");
while (x < 20)
{
if (x == 5){
break; // breaks out of loop completely
}
x = x + 1;
document.write( x + "<br />");
}
document.write("Exiting the loop!<br /> ");
var x = 1;
document.write("Entering the loop<br /> ");
while (x < 10)
{
x = x + 1;
if (x == 5){
continue; // skill rest of the loop body
}
document.write( x + "<br />");
}
document.write("Exiting the loop!<br /> ");
Functions
A function is a group of reusable code which can be called anywhere in your program.
This eliminates the need of writing the same code again and again.
It helps programmers in writing modular codes.
Functions allow a programmer to divide a big program into a number of small and manageable
functions.
Like any other advanced programming language, JavaScript also supports all the features
necessary to write modular code using functions.
You must have seen functions like alert() and write() in the earlier chapters.
We were using these functions again and again, but they had been written in core JavaScript only once.
JavaScript allows us to write our own functions as well.
A function can be written using one of the below 3 methods supported by JavaScript
A function statement
A function constructor
A function literal
Functions - Function Definition
Before we use a function, we need to define it.
The most common way to define a function in JavaScript is
by using the function keyword,
followed by a unique function name,
a list of parameters (that might be empty),
and a statement block surrounded by curly braces.
function functionname(parameter-list)
{
statements
}
Functions Calling a function, parameters and return value
Calling a Function, and Function Parameters
function sayHello(name, age)
{
document.write (name + " is " + age + " years old.");
}
sayHello('Zara', 7); // calling a function
The return Statement
function concatenate(first, last)
{
var full;
full = first + last;
return full;
}
function secondFunction()
{
var result;
result = concatenate('Zara', 'Ali');
document.write (result );
}
secondFunction(); // calling a function
Functions - Default function parameters
Default function parameters allow formal parameters to be initialized with default values if no
value or undefined is passed.
In JavaScript, parameters of functions default to undefined.
However, in some situations it might be useful to set a different default value.
This is where default parameters can help.
This even applies to functions and variables:
callSomething(); //sth
Functions - Arguments object
The arguments object is an Array-like object corresponding to the arguments passed to a function.
The arguments object is a local variable available within all functions.
You can refer to a function's arguments within the function by using the arguments object.
This object contains an entry for each argument passed to the function, the first entry's index starting at 0.
For example, if a function is passed three arguments, you can refer to them as follows:
arguments[0]
arguments[1]
arguments[2]
The arguments object is not an Array. It is similar to an Array, but does not have any Array properties
except length. For example, it does not have the pop method. However it can be converted to a real Array:
Functions - Rest parameters
The rest parameter syntax allows us to represent an indefinite number of arguments as an array.
function f(a, b, ...theArgs) {
// ...
}
If the last named argument of a function is prefixed with ..., it becomes an array whose elements from 0
(inclusive) to theArgs.length (exclusive) are supplied by the actual arguments passed to the function.
In the above example, theArgs would collect the third argument of the function (because the first one is
mapped to a, and the second to b) and all the consecutive arguments.
function fun1(...theArgs) {
console.log(theArgs.length);
}
fun1(); // 0
fun1(5); // 1
fun1(5, 6, 7); // 3
Functions - Rest parameters vs Arguments object
There are three main differences between rest parameters and the
arguments object:
rest parameters are only the ones that haven't been given a separate name,
while the arguments object contains all arguments passed to the function.
the arguments object is not a real array, while rest parameters are Array
instances, meaning methods like sort, map, forEach or pop can be applied on
it directly.
the arguments object has additional functionality specific to itself (like the
callee property).
Functions Nested functions
JavaScript 1.2 allows function definitions to be nested within other functions as well.
Still there is a restriction that function definitions may not appear within loops or conditionals.
These restrictions on function definitions apply only to function declarations with the function
statement.
Whereas function literals (another feature introduced in JavaScript 1.2) may appear within any
JavaScript expression, which means that they can appear within if and other statements.
function hypotenuse(a, b) {
function square(x) { return x*x; }
return Math.sqrt(square(a) + square(b));
} JavaScript functions implement the concept of closures, which are functions that
function secondFunction(){ are defined inside other functions, and use contextual data from the parent
var result; functions to execute.
result = hypotenuse(1,2);
document.write ( result );
}
secondFunction(); // Calling function
Functions Function() constructor
The function statement is not the only way to define a new function; you can define your function
dynamically using Function() constructor along with the new operator.
Notice that the Function() constructor is not passed any argument that specifies a name for the
function it creates.
The unnamed functions created with the Function() constructor are called anonymous functions.
var variablename = new Function(arg1, arg2,..., argN, "Function Body");
var func = new Function("x", "y", "return x*y;");
function secondFunction(){
var result;
result = func(10,20);
document.write ( result );
}
function secondFunction(){
var result;
result = func(10,20);
document.write ( result );
}
The set syntax binds an object property to a function to be called when there is an attempt to set that
property.
If you want to remove the setter, you can just delete it: delete o.current;
Example
var person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
Spaces and line breaks are not important. An object definition can span multiple lines:
Example
var person = {
firstName:"John",
lastName:"Doe",
age:50,
eyeColor:"blue"
};
Object creation Creating an object using object literal
Objects created using object literals are singletons.
This means when a change is made to the object will reflect to all
other instances of that object.
Object creation Using the JavaScript Keyword new
The following example also creates a new JavaScript object with four
properties:
Example
person.firstName = "John";
person.lastName = "Doe";
person.age = 50;
person.eyeColor = "blue";
The two examples above do exactly the same. There is no need to use new
Object().
For simplicity, readability and execution speed, use the first one (the object
literal method)
Object creation Using an object constructor
The examples above are limited in many situations. They only create a single object.
Sometimes we like to have an "object type" that can be used to create many objects of one type.
The standard way to create an "object type" is to use an object constructor function:
myBook.addPrice(100);
document.write("Book title is : " + myBook.title + "<br>");
document.write("Book author is : " + myBook.author + "<br>");
document.write("Book price is : " + myBook.price + "<br>");
Object creation Using an object constructor
This example demonstrates how to create an object with a function literal.
Here this keyword is used to refer to the object that has been passed to a function.
A function literal
Object creation Using an object constructor
Built-in JavaScript Constructors : JavaScript has built-in constructors for native objects:
Example
var x1 = new Object(); // A new Object object
var x2 = new String(); // A new String object
var x3 = new Number(); // A new Number object
var x4 = new Boolean(); // A new Boolean object
var x5 = new Array(); // A new Array object
var x6 = new RegExp(); // A new RegExp object
var x7 = new Function(); // A new Function object
var x8 = new Date(); // A new Date object
There is no reason to create complex objects. Primitive values execute much faster.
And there is no reason to use new Array(). Use array literals instead: []
And there is no reason to use new RegExp(). Use pattern literals instead: /()/
And there is no reason to use new Function(). Use function expressions instead: function () {}.
And there is no reason to use new Object(). Use object literals instead: {}
Example
var x1 = {}; // new object
var x2 = ""; // new primitive string
var x3 = 0; // new primitive number
var x4 = false; // new primitive boolean
var x5 = []; // new array object
var x6 = /()/ // new regexp object
var x7 = function(){}; // new function object
Objects - Properties and Methods
Object properties can be any of the three primitive data types, or any of the abstract
data types, such as another object.
Object properties are usually variables that are used internally in the object's methods,
but can also be globally visible variables that are used throughout the page.
objectName.objectProperty = propertyValue;
Example - var str = document.title;
Object Methods are useful for everything from displaying the contents of the object to
the screen to performing complex mathematical operations on a group of local
properties and parameters.
document.write ("This is test"); //to show how to use the write() method of document object to write content on document
Objects - The this Keyword
In JavaScript, the thing called this, is the object that "owns" the JavaScript code.
The value of this, when used in a function, is the object that "owns" the function.
this is undefined in a function invocation in strict mode
The value of this, when used in a method of an object, is the object itself.
The value of this, is the newly created object in a constructor invocation
The value of this, in an indirect invocation is the value passed as first argument to .call() or .apply().
this is the first argument of .bind() when invoking a bound function
Note that this is not a variable. It is a keyword. You cannot change the value of this.
https://rainsoft.io/gentle-explanation-of-this-in-javascript/#2functioninvocation
Objects - The with Keyword
The with keyword is used as a kind of shorthand for referencing an object's properties or
methods.
The object specified as an argument to with becomes the default object for the duration of the
block that follows.
The properties and methods for the object can be used without naming the object.
The syntax for with object is as follows:
with (object){
properties used without the object name and dot
}
// Define a function which will work as a method
function addPrice(amount){
with(this){
price = amount;
}
}
Objects - JavaScript Object Prototypes
Every JavaScript object has a prototype.
All JavaScript objects inherit their properties and methods from their
prototype.
Objects created with new Date() inherit the Date.prototype.
Objects - Creating a Prototype
The standard way to create an object prototype is to use an object constructor function:
Example
function Person(first, last, age, eyecolor) {
this.firstName = first;
this.lastName = last;
this.age = age;
this.eyeColor = eyecolor;
}
With a constructor function, you can use the new keyword to create new objects from the same prototype:
Example
var myFather = new Person("John", "Doe", 50, "blue");
var myMother = new Person("Sally", "Rally", 48, "green");
Objects - Adding Properties and Methods to Objects
var myFather = new Person("John", "Doe", 50, "blue");
var myMother = new Person("Sally", "Rally", 48, "green");
The property will be added to myFather. Not to myMother. Not to any other person objects.
Person.prototype.nationality = "English";
Person.prototype.name = function() {
return this.firstName + " " + this.lastName;
};
Objects - Private Members
JavaScript doesn't support the notion of private members as C# does, but you can simulate the
functionality by using variables inside the function.
Variables are declared with the var keyword or are received as function parameters.
They aren't accessed using this, and they aren't accessible through function instances, thus acting like private
members.
Variables can, however, be accessed by closure functions
function Table (rows, columns){
// save parameter values to local variables
var _rows = rows;
var _columns = columns;
// return the number of table cells
this.getCellCount = function() { return _rows * _columns; };
}
// display object field values Your table has undefined rows and undefined columns
document.write("Your table has " + t._rows + " rows" + " and " + t._columns + " columns<br />");
When implementing inheritance through prototyping, we can "load" the base class properties
and methods by adding them to the derived class prototype.
That way, an object of the derived class will have access to the class methods and properties, but
also to the base class methods and properties since they exist in the derived class prototype.
Objects - Inheritance Using Prototyping
Objects - Polymorphism in JavaScript
Polymorphism in JavaScript is now very easy.
One simply makes different constructors for different kinds of child
objects inheriting from the same parent.
JavaScript polymorphism has a feature one does not find in all object-
oriented languages.
One can add and override members even on the fly, after an object has been
created.
An object can acquire or lose properties and behaviours over time.
Objects - Polymorphism using prototype
JavaScript Classes
JavaScript classes introduced in ECMAScript 2015 are primarily syntactical
sugar over JavaScript's existing prototype-based inheritance.
The class syntax is not introducing a new object-oriented inheritance
model to JavaScript.
JavaScript classes provide a much simpler and clearer syntax to create
objects and deal with inheritance.
Classes are in fact "special functions", and just as you can define function
literals and function statements, the class syntax has two components:
class expressions (or class literals)
class declarations (or class statements)
Defining classes - class declaration
One way to define a class is using a class declaration. To declare a class, you use the class keyword with the name of the
class ("Rectangle" here).
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
}
Hoisting
An important difference between function declarations and class declarations is that function declarations are hoisted and
class declarations are not.
You first need to declare your class and then access it, otherwise code like the following will throw a ReferenceError:
var p = new Rectangle(); // ReferenceError
class Rectangle {}
Defining classes - class expression
A class expression is another way to define a class. Class expressions can be named or unnamed.
The name given to a named class expression is local to the class's body.
// unnamed
var Rectangle = class {
constructor(height, width) {
this.height = height;
this.width = width;
}
};
// named
var Rectangle = class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
};
Note: Class expressions also suffer from the same hoisting issues mentioned for Class
declarations.
Defining classes - Constructor method
The constructor method is a special method for creating and initializing an object created with a class.
constructor([arguments]) { ... }
There can only be one special method with the name "constructor" in a class.
A SyntaxError will be thrown, if the class contains more than one occurrence of a constructor method.
A constructor can use the super keyword to call the constructor of a parent class.
console.log(Point.distance(p1, p2));
Defining classes - Sub classing with extends
The extends keyword is used in class declarations or class expressions to create a class as a child of another class.
If there is a constructor present in sub-class, it needs to first call super() before using "this".
One may also extend traditional function-based "classes
Note that classes cannot extend regular (non-constructible) objects. If you want to inherit from a regular object, you can
instead use Object.setPrototypeOf():
class Animal { function Animal (name) { var Animal = {
constructor(name) { this.name = name; speak() {
this.name = name; console.log(this.name + ' makes a noise.');
}
} }
};
speak() { Animal.prototype.speak = function () {
console.log(this.name + ' makes a noise.'); console.log(this.name + ' makes a noise.'); class Dog {
} } constructor(name) {
} this.name = name;
}
class Dog extends Animal {
class Dog extends Animal { }
speak() { speak() {
console.log(this.name + ' barks.'); console.log(this.name + ' barks.'); // If you do not do this you will get a TypeError when you invoke speak
} } Object.setPrototypeOf(Dog.prototype, Animal);
} }
var d = new Dog('Mitzie');
var d = new Dog('Mitzie'); d.speak(); // Mitzie makes a noise.
var d = new Dog('Mitzie');
d.speak(); // Mitzie barks.
d.speak(); // Mitzie barks.
Defining classes - Super class calls with super
The super keyword is used to call functions on an object's parent.
class Cat {
constructor(name) {
this.name = name;
}
speak() {
console.log(this.name + ' makes a noise.');
}
}
every() Returns true if every element in this array satisfies the provided testing function.
filter() Creates a new array with all of the elements of this array for which the provided filtering function returns true.
indexOf() Returns the first (least) index of an element within the array equal to the specified value, or -1 if none is found.
lastIndexOf() Returns the last (greatest) index of an element within the array equal to the specified value, or -1 if none is found.
map() Creates a new array with the results of calling a provided function on every element in this array.
pop() Removes the last element from an array and returns that element.
push() Adds one or more elements to the end of an array and returns the new length of the array.
reduce() Apply a function simultaneously against two values of the array (from left-to-right) as to reduce it to a single value.
reduceRight() Apply a function simultaneously against two values of the array (from right-to-left) as to reduce it to a single value.
reverse() Reverses the order of the elements of an array -- the first becomes the last, and the last becomes the first.
shift() Removes the first element from an array and returns that element.
some() Returns true if at least one element in this array satisfies the provided testing function.
unshift() Adds one or more elements to the front of an array and returns the new length of the array.
Array Methods
var alpha = ["a", "b", "c"]; function printBr(element, index, array) { var arr = new
var numeric = [1, 2, 3]; document.write("<br />[" + index + "] is " + element ); Array("First","Second","Third");
}
var alphaNumeric = alpha.concat(numeric); var str = arr.join();
document.write("alphaNumeric : " + alphaNumeric ); [12, 5, 8, 130, 44].forEach(printBr); document.write("str : " + str );
var arr = new Array("orange", "mango", "banana", "sugar"); Returned array is : water,orange,mango,banana,sugar
var sorted = arr.sort(); Length of the array is : 5
document.write("Returned string is : " + sorted );
Number Properties
MAX_VALUE The largest possible value a number in JavaScript can have 1.7976931348623157E+308
MIN_VALUE The smallest possible value a number in JavaScript can have 5E-324
NaN Equal to a value that is not a number.
NEGATIVE_INFINITY A value that is less than MIN_VALUE.
POSITIVE_INFINITY A value that is greater than MAX_VALUE
prototype A static property of the Number object. Use the prototype property to assign new properties and methods to the Number object in the current document
constructor Returns the function that created this object's instance. By default this is the Number object.
Number Methods
toExponential() Forces a number to display in exponential notation, even if 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() Defines how many total digits (including digits to the left and right of the decimal) to display of a number.
toString() Returns the string representation of the number's value.
valueOf() Returns the number's value.
var num = new Number(15);
document.write("num.toString() is " + num.toString());
document.write("<br />");
Boolean
The Boolean object represents two values, either "true" or "false".
Use the following syntax to create a boolean object.
var val = new Boolean(value);
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.
Boolean Properties
Constructor - Returns a reference to the Boolean function that created the object.
boolean.constructor()
Prototype - The prototype property allows you to add properties and methods to an object.
object.prototype.name = value
Boolean Methods
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.
Boolean
var bool = new Boolean( );
document.write("bool.constructor() is : " + bool.constructor);
-------------------------------------------------------------------------------------------------------
-
function book(title, publisher)
{
this.title = title;
this.publisher = publisher;
}
var str1 = new String( "This is string one" ); var str = "Apples are round, and Apples are Juicy.";
var index = str1.indexOf( "string" ); document.write(str.toString( ));
document.writeln("indexOf found String :" + index );
var str = "Apples are round, and Apples are Juicy.";
var str1 = new String( "This is string one and again string" ); document.write(str.toUpperCase( ));
var index = str1.lastIndexOf( "string" );
document.write("lastIndexOf found String :" + index ); var str = new String("Hello world");
document.write(str.valueOf( ));
var re = /apples/gi;
var str = "Apples are round, and apples are juicy.";
var newstr = str.replace(re, "oranges");
document.write(newstr );
getDate() Returns the day of the month for the specified date according to local time.
getDay() Returns the day of the week for the specified date according to local time.
getFullYear() Returns the year of the specified date according to local time.
getHours() Returns the hour in the specified date according to local time.
getMilliseconds() Returns the milliseconds in the specified date according to local time.
getMinutes() Returns the minutes in the specified date according to local time.
getMonth() Returns the month in the specified date according to local time.
getSeconds() Returns the seconds in the specified date according to local time.
getTime() Returns the numeric value of the specified date as the number of milliseconds since January 1, 1970, 00:00:00 UTC.
toLocaleTimeString() Returns the "time" portion of the Date as a string, using the current locale's conventions.
toSource() Returns a string representing the source for an equivalent Date object; you can use this value to create a new object.