I'm testing Onclick on JS and I'm strange about a business, it works only when I paste it into the document.querySelector('.a').onclick = teste2();
console, or the first time I run / open the page. If I click on the element I'm catching, it does not work. Why?
<html>
<head></head>
<meta charset="utf-8">
<body>
<div class="a">Testando...</div>
<script>
let teste2 = () => alert(this === window);
document.querySelector('.a').onclick = teste2();
</script>
</body>
</html>