javastrip中点击销毁计时器再次点击创建计时器

javastrip中点击销毁计时器再次点击创建计时器,有无人指教下


<html xmlns="http://www.w3.org/1999/xhtml">

    <head>
        <title>无标题页</title>
        <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
    </head>

    <body>
        <button id="app">计时器</button>
        <script>
            let timer = null
            $('#app').click(function () {
                console.log('timer', timer)
                if (timer) {
                    clearInterval(timer)
                } else {
                    timer = setInterval(() => {
                        console.log(1)
                    }, 1000)
                }
            })
        </script>
    </body>


</html>