Right way to change HTML element when the element is saved as a constant (Uncaught TypeError: Assignment to constant variable)

Viewed 188

Im trying to change the documents html text (value). It is working but it also gives this error Uncaught TypeError: Assignment to constant variable. Is there another way to replace the value?

//The element
let items = 1
const itemCountSpan = document.getElementById('item-count')
itemCountSpan.innerHTML = items
1 Answers

A constant is a value that cannot be altered by the program during normal execution. It cannot change through re-assignment, and it can't be redeclared. In JavaScript, constants are declared using the const keyword. Source. So, if you want to avoid that error use let

Related