So i started learning Javascript a few weeks ago from an online course. I got up to a point where i started learning the DOM manipulation and there's an exercise to generate a random colours for the background. At first i saved the random colour to a let variable. But when i see the answer for the exercise, it uses a const not let. How is this possible, I thought const can't be redeclared?
function randomColour() {
const r = Math.floor(Math.random() * 255);
const g = Math.floor(Math.random() * 255);
const b = Math.floor(Math.random() * 255);
return `rgb(${r},${g},${b}`;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…