Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda