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

128
Vistas
Compare 2 elements

Below is a typical way to check if the focus is on an element certain (txtCmd),

if(document.activeElement === txtCmd){
                return
}

I'm worried the operator=== would compare the entire element tree (every attribute and every sub-element) that would be low performance.

Does just compare the elements' Ids is better?

document.activeElement.id === txtCmd.id

PS: There are no different elements with identical ID in the page.

Edit:

I'm from C++. I want something like pointer comparison in C++,

   if(&a == &b) {}
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

=== doesn’t perform any deep comparisons, so it’s not low-performance.

An alternative is the .isSameNode() function:

b.isSameNode(a);

Edit:

I'm from C++. I want something like pointer comparison in C++,

if(&a == &b) {}

That essentially is what == and === do in JavaScript when 2 objects are tested for equality.

JavaScript’s quality operators compare objects by reference if the operands are both objects. a == b and a === b are true only if both a and b reference the same object.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you compare objects the === operator will perform a reference comparison, so it will only return true only if both operands points to the same object.

It will not cost you more performances but it just does not the same thing than comparing property litteral values.

For a deep comparison "by value" between objects, === doesn't work. You'd have to use a recursive entry by entry comparison, or compare stringified versions of the objects.

Example

const o1 = {"a":1};
const o2 = {"a":1};
const o3 = o1;
console.log(o1 === o2); // false
console.log(o1 === o3); // true
console.log(JSON.stringify(o1) === JSON.stringify(o2)) // true

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