JavaScript | Date constructor Property

In JavaScript, The Date constructor property returns the constructor function for an object. For JavaScript Date constructor property returns function Date() { [native code] }.

Syntax:

Date.constructor

Example 1: This example uses constructor property and returns the date constructor function.



filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>
            JavaScript | Date constructor Property
        </title>
    </head>
    <body>
        <center>
            <div style="background-color: green;">
                  
                <h1>Welcome to GeeksforGeeks!.</h1>
                  
                <p> 
                    It returns the function that 
                    created the string's prototype:
                </p>
                  
                <h1 id="demo"></h1>
            </div>
        </center>
          
        <script>
            var dy = new Date();
            document.getElementById("demo").innerHTML
                    = dy.constructor;
        </script>
    </body>
</html>

chevron_right


Output:
BERJAYA

Example 2: This example uses constructor property and returns the date constructor function.

filter_none

edit
close

play_arrow

link
brightness_4
code

<!DOCTYPE html>
<html>
    <head>
        <title>
            JavaScript | Date constructor Property
        </title>
    </head>
    <body>
        <center>
            <div style="background-color: white;">
                  
                <h1>Welcome to GeeksforGeeks!.</h1>
                  
                <h3>
                    It returns the function that created
                    the string's prototype:
                </h3>
                  
                <p id="name" style="background-color:green;">
                </p>
            </div>
        </center>
        <script>
            var dy = new Date();
            document.getElementById("name").innerHTML
                    = dy.constructor;
        </script>
    </body>
</html>

chevron_right


Output:
BERJAYA

Supported Browsers: The browsers supported by JavaScript Date constructor Property are listed below:

  • Google Chrome
  • Interent Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

BERJAYA
Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.