HOME HTML CSS JAVASCRIPT SQL PHP JQUERY XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript constructor Property

Math Object Reference Complete Math Object Reference

Definition and Usage

The constructor property is a reference to the function that created an object.

Syntax

object.constructor


Example 1

In this example we will show how to use the constructor property:

<script>

var test=new Date();
if (test.constructor==Array)
{
document.write("This is an Array");
}
if (test.constructor==Boolean)
{
document.write("This is a Boolean");
}
if (test.constructor==Date)
{
document.write("This is a Date");
}
if (test.constructor==String)
{
document.write("This is a String");
}

</script>

The output of the code above will be:

This is a Date

Try it yourself »

Example 2

In this example we will show how to use the constructor property:

<script>
function employee(name,jobtitle,born)
{
this.name=name;
this.jobtitle=jobtitle;
this.born=born;
}

var fred=new employee("Fred Flintstone","Caveman",1970);

document.write(fred.constructor);

</script>

The output of the code above will be:

function employee(name, jobtitle, born)
{this.name = name; this.jobtitle = jobtitle; this.born = born;}

Try it yourself »

Math Object Reference Complete Math Object Reference

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE