I am trying the ES6 destructuring assignment feature to pass an options object containing multiple parameters to a function, but one of the parameters is being overridden by a DOM element with the same id!
//javascript function call:
createPicture({name: "aaa", width: 100, height: 100, tags: [] })
//javascript function declaration:
createPicture({name, width, height, tags}) {
console.log(tags) //prints a DOM element with id "tags" instead of an empty array!
}
I know that DOM elements with ids create global variables in JS, but it is really weird to me that it overrides the attributes within the object in the function call. there is some way to protect the javascript code?
EDIT: I added a JSFiddle as suggested to confirm the issue. the problem appears if in the function declaration tags has a default value. if it is let empty, then there is no error. Fiddle here