const canvas = document.getElementById("game");
const context = canvas.getContext("2d");
context.fillStyle = "#000000";
context.fillRect(0, 0, canvas.width, canvas.height);
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript" src="code.js"></script>
<canvas id="game" width="600" height="400"></canvas>
<title>Game</title>
</head>
<body>
</body>
</html>
Estoy intentando dibujar un cuadrado negro pero al ejecutar me aparece este error: "Cannot read properties of null (reading 'getContext')".