Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript Date constructor Property

  • Last Updated : 12 Oct, 2021

Below is the example of the Date constructor property. 
 

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

  • Example:

JavaScript




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

html




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

html




<!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 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Internet Explorer 8 and above
  • Opera 3 and above
  • Safari 1 and above



My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!