JavaScript Date constructor Property

Below is the example of the Date constructor property.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type = "text/javascript"
        var date = new Date(); 
        document.write("Date.constructor:"
                + date.constructor); 
    </script>    

    chevron_right

    
    

  • Output:
    Date.constructor:function Date() { [native code] }

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

Return value: It returns the function Date() { [native code] }.

More example codes for the above property are as follows:
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 style="text-align:center;"
  
    <div
              
        <h1 style="color: green;">GeeksforGeeks</h1
                  
        <p
            JavaScript Date constructor Property 
            returns the function that created the 
            Date's prototype: 
        </p
                  
        <b id="GFG"></b
          
    </div
      
    <!-- Script to use date constructor -->
    <script
        var dy = new Date();
        document.getElementById("GFG").innerHTML 
                = dy.constructor; 
    </script
</body
  
</html>              

chevron_right


Output:

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 style="text-align:center;"
  
    <div
              
        <h1 style="color: green;">GeeksforGeeks</h1
                  
        <p
            JavaScript Date constructor Property 
            returns the function that created 
            the Date's prototype: 
        </p
        <button onclick="gfg()">Click me</button
        <p id="GFG"></p
    </div
      
    <!-- Script to use Date constructor Property -->
    <script
    function gfg(){ 
        var dy = new Date();
        document.getElementById("GFG").innerHTML 
                = dy.constructor; 
    
    </script
</body
  
</html>  

chevron_right


Output:

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

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

full-stack-img




My Personal Notes arrow_drop_up

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.