I have tried every format of doing this, and nothing seems to work, please help!
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="script.js"></script>
</head>
<body>
    <button id="btn">Click me</button>
</body>
</html>
JavaScript:
let btn = document.getElementById('btn');
btn.addEventListener('click', func());
function func(){
    alert('hello');
};
The error it returns is:
script.js:3 Uncaught TypeError: Cannot read properties of null (reading 'addEventListener') at script.js:3:5
 
     
    
` without the `defer` and it would work.
– disinfor Jan 15 '22 at 18:39