Skip to content
Related Articles

Related Articles

JavaScript Date constructor Property
  • Last Updated : 27 Jun, 2020
GeeksforGeeks - Summer Carnival Banner

Below is the example of the Date constructor property.

  • Example:




    <script type = "text/javascript"
        var date = new Date(); 
        document.write("Date.constructor:"
                + date.constructor); 
    </script>     
  • 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.






<!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>                 

Output:

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




<!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>     

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
Recommended Articles
Page :