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

202
Vistas
Why is this JavaScript function working when it should throw an error?

I use a shorthand function to avoid having to type let x = document.getElementById('myId'); every time I want a reference to an element on the page:

function element(id) {
    return document.getElementById(id);
}

Now I can just use the much simpler:

let x = element("id");

Today, by accident, I did this:

let x = element("id").value;

And it worked, and actually contained the value of the HTML element "id".

But my element() function doesn't provide a .value property. It simply returns a reference to an element.

It should have caused an error of some type. Why didn't it? Or why did it work?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You've accessed a .value property of a function result, not of a function itself.

element.value // undefined, gets value property of a function
element(id).value // gets an element by id and returns it's value
about 4 years ago · Juan Pablo Isaza Denunciar
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