Why is my DomDocument not working but it is in console [duplicate]

I made a simple project
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>
</head>
<body>
    <script src="script.js"></script>
    <canvas id="screwen">

    </canvas>
</body>
</html>

Javascript:

const GameWindow = document.getElementById('screwen')

But in console it saying GameWindow is null
console:

document.getElementById('screwen')
<canvas id=​"screwen">​ ​</canvas>​

const Hello = document.getElementById('screwen')
undefined
Hello
<canvas id=​"screwen">​ ​</canvas>​

GameWindow
null

Why is it like that?