'trail' is never reassigned. Use 'const' instead
12let speedY = 0;
13let playerX = 10;
14let playerY = 10;
15let trail = []; 16let tail = 5;
17
18let appleX = 15;
'canvas' is never reassigned. Use 'const' instead
1window.onload = function () {
2 let canvas = document.getElementById("canvas"); 3 context = canvas.getContext("2d");
4 document.addEventListener("keydown", keyPush);
5 setInterval(game, 1000 / 15);
Description
Variables that are never re-assigned a new value after their initial declaration should be declared with the const
keyword.
This prevents the programmer from erroneously re-assigning to a read-only variable, and informs those reading the code that a variable is a constant value.
Bad Practice
let pi = Math.PI
for (let x of xs) {
use(x);
}
let { a, b } = object;
use(a, b);
Recommended
const pi = Math.PI
for (const x of xs) {
use(x);
}
const { a, b } = object;
use(a, b);