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

335
Views
¿Cómo funciona realmente el operador instanceof en JS?

He buscado en el sitio esta pregunta y obtuve la siguiente respuesta:

 function instance_of(V, F) { var O = F.prototype; V = V.__proto__; while (true) { if (V === null) return false; if (O === V) return true; V = V.__proto__; } }

Es de https://stackoverflow.com/a/9220317/12974414 .

Pero probé el siguiente código, encontré algo extraño:

 console.log( (10).__proto__ === Number.prototype ) // true console.log( instance_of(10, Number ) ) // true console.log( 10 instanceof Number ) // false function instance_of(V, F) { var O = F.prototype; V = V.__proto__; while (true) { if (V === null) return false; if (O === V) return true; V = V.__proto__; } }

¿Cómo explicar esto y cómo funciona realmente el operador instanceof en JS?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

JavaScript tiene una función llamada autoboxing que convierte las primitivas en objetos cuando intenta acceder a las propiedades en ellos.

instanceof no autobox y un número primitivo no es una instancia de la clase Number.

Puedes ver, en la especificación :

  1. Si Tipo(O) no es Objeto, devuelve falso.
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!