Memory overflow caused by the first parameter of setTimeout without quotation marks

Web page display online time: `

    var timeblc = document.getElementById("nowtime");
    var weekdays = ["", "", "", "", "", "", ""];
    function addZero(t){
        if(t<10) return "0"+t;
        return t;
    }
    function showTime(){
        var time = new Date();
        var t = time.getFullYear()+""+getMonthDay(time)+getWeekday(time)+getHMS(time);
        timeblc.innerHTML = t;
        setTimeout("showTime()",1000);      //
    }
    function getMonthDay(time){
        var m = addZero(time.getMonth()+1);
        var d = addZero(time.getDate());
        var str = m+""+d+"";
        return str;
    }
    function getWeekday(time){
        var str = weekdays[time.getDay()];
        return str;
    }
    function getHMS(time){
        var h = addZero(time.getHours());
        var m = addZero(time.getMinutes());
        var s = addZero(time.getSeconds());
        var str = h+":"+m+":"+s;
        return str;
    }
    showTime();`
At the

code comment, the first parameter will cause a memory overflow if it does not add quotation marks:

after checking on the Internet, we can see that quotation marks will look for it globally, and if not, it will look for local variables. However, there is no relationship between the overflow and the way variables are queried.

ask for advice!

Mar.28,2021

the first argument to setTimeout should be the function to be executed

setTimeout(showTime, 1000);

execute the function showTime without quotation marks. This creates a recursive dead loop. The setTimeout function call is written as follows:

  1. setTimeout (fn, timeout)
  2. setTimeout ('fn ()', timeout)
Menu