Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

130
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!