ClearTimeout doesn't work.

when using a timer, there are two buttons, one is to set the timer and the other is to clear the timer, but clearTimeout does not work and the output is still on the console. Why and what went wrong? The
code is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script>
       var settime=null;
        function insert(){
            settime=window.setTimeout(showalert,3000);
        }
        function showalert(){
            console.log("");
        }
        function clear(){
            window.clearTimeout(settime);
        }
    </script>
</head>
<body>
    <div id="a">
      <h3>setTimeout</h3>
      <button onclick="insert()"></button>
      <button onclick="clear()"></button>
    </div>
</body>
</html>
Mar.03,2021

Ah, man, I've encountered this kind of problem before, and I don't know what to do.
reason: clear is a keyword, you can try to change its name, such as clear1.

-add
Sorry, the answer is not quite correct.
you can try this (the following code), and it will print out: "clear () {[native code]}.
states that there is a clear method in the internal scope of event handling that ranks higher and behaves as if it always overrides your defined clear method.

<button onclick="(function() { console.log(clear) })()">Click</button>

the name of the function that your cancel button will not execute is the keyword


    
    timeout
    ```
    function insert(){
        if(settime) window.clearTimeout(settime);
        settime=window.setTimeout(showalert,3000);
    }
    
    function clear(){
        if(settime) {
            window.clearTimeout(settime);
            settime = null;
        }        
    }
    
    ```
    cleardocumentapi:
    
    ```
    <script>
        document.clear = function(){
            console.log("clear");
        }
    </script>
    <a href="-sharp" onclick="clear()">click me</a>

    ```
    
.
Menu