Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
I am confused - I receive "getMonth is not a function"

even though i assigned a date to the variable, I receive the error message "getMonth is not a function"

Obviously the interpretor does not accept the type of date.

This is th relevant section of the code:

function init(){
            var m=document.getElementById("m");
            var d = Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();

yes, the function is terminated by a } there are more lines to it, but it stops exactly there.

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You forgot to use new keyword with Date :

function init(){
  var m=document.getElementById("m");
  var d = new Date();
  refresh(d);
}


function refresh(d) {
  var month = d.getMonth();
  console.log(month)

}

init()

about 4 years ago · Juan Pablo Isaza Report

0

You seem to want to get the constructor, while you're currently defining the function as d.

Read more about Date here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

So, the code fragment should be:

function init(){
            var m=document.getElementById("m");
            var d = new Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();
about 4 years ago · Juan Pablo Isaza Report

0

Date is a class in javascript, so you need to use the new keyword to create a new instance and call methods like getMonth on it.

function init(){
            var m=document.getElementById("m");
            var d = new Date();
            refresh(d);
        }


        function refresh(d) {
                var month = d.getMonth();
                console.log(month);
        }
        
        init();

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!