My mind has blown. I have a code wich looks (exactly) like this
const A={
B:document.getElementById("plus")
}
A.B.addEventListener("click",()=>{
console.log("1")
})
When i run it, it says "A.B" is null. I tried different versions, but still nothing. Then I copied it right into console and it worked just as expected. I put some console.log statements between object and event listener, and indeed, A and A.B both are null. Though in console they were not. What am I doing wrong?
EDIT: HTML
<!DOCTYPE html >
<html>
<head>
//some other staff
<script src="main.js"></script>
</head>
<body>
<button type="button" id="plus">+</button>
</body>