JavaScript Not Automatically Deleting Variable After Instructed

I made a script that creates an HTML tag using JavaScript. I declared a variable called tag, specifically knowing you can’t delete() let and var variables, but it won’t automatically delete it in my code:


function(tagType, attr1 = null, value1 = null, attr2 = null, value2 = null, attr3 = null, value3 = null, attr4 = null, value4 = null, attr5 = null, value5 = null, attr6 = null, value6 = null, attr7 = null, value7 = null, attr8 = null, value8 = null, attr9 = null, value9 = null, attr10 = null, value10 = null) {
  tag = document.createElement(tagType);
  if (attr1 != null) {
    tag.setAttribute(attr1, value1)
  };
  if (attr2 != null) {
    tag.setAttribute(attr2, value2)
  };
  if (attr3 != null) {
    tag.setAttribute(attr3, value3)
  };
  if (attr4 != null) {
    tag.setAttribute(attr4, value4)
  };
  if (attr5 != null) {
    tag.setAttribute(attr5, value5)
  };
  if (attr6 != null) {
    tag.setAttribute(attr6, value6)
  };
  if (attr7 != null) {
    tag.setAttribute(attr7, value7)
  };
  if (attr8 != null) {
    tag.setAttribute(attr8, value8)
  };
  if (attr9 != null) {
    tag.setAttribute(attr9, value9)
  };
  if (attr10 != null) {
    tag.setAttribute(attr10, value10)
  };
  document.getElementsByTagName('head')[0].appendChild(tag);
  if (tag) {
    delete(this.tag);
  }
},

In the end of the code, I said delete(tag), and it didn’t work. So then I tried checking if variable named tag was there. if(tag) { delete(tag) }.

Why isn’t it automatically deleting the variable? If I just type delete(tag) into the console, it will delete it.

Thank you for your help!