Could you tell me what am I doing wrong? According to my criteria the code should run fine but the problem is that it gives me an error element
when I call it in the first function to give it a value, according to javascript this should have a variable declaration but it is already set as global and already tried testing withthis
const element = ''
const createSpanTag = () => {
element = document.createElement('span')
element.setAttribute('id', `stElement${auto}`)
element.setAttribute('class', 'stElement')
return element
}
When I replicated your code on my machine the error I got was this:
This error occurs because you are using one
const
to store data that you are then going to modify or manipulate to mutate. The data or variablesconst
are immutable, as their name says, they are values that are always kept constant.You should change your first line to a
let
instead of aconst
now this will give you another error which is because${auto}
I guess you must have declared it higher up in your code.Another way to solve your problem would be to declare
const element
inside the method, with this you could assign its values to create your element without problems. Example:I hope my answer helps you. Cheers !.
AS A GOOD PRACTICE
It is customary for global type variables
const
to put their names in UPPERCASE. Example: