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

317
Vistas
What is new Number(122) in Javascript

I saw a question here -> https://github.com/lydiahallie/javascript-questions#answer-c-1

Consider the below code snippet.

let a = 3;
let b = Number(3)
let c = new Number(3)

a == b // true
a === b // true
// but
a===c or b === c // false

The situation is also explained in the above repo, but I would like to know what are the other features of this c object.

I also tried to see its properties or methods in the browser console, and I found that it is the same as a, the methods are toFixed, etc.

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

0

new Number creates a wrapper object.

To get its primitive value, you can use Number#valueOf:

let a = 3, b = Number(3), c = new Number(3);

console.log(typeof c);

console.log(a === c.valueOf());
console.log(b === c.valueOf());

about 4 years ago · Juan Pablo Isaza Denunciar

0

Because

let a = 3; // is a number
let b = Number(3) // is a number
let c = new Number(3) // is an object

a == b // true
a === b // true
// but
a===c or b === c // false

Is that clear?

about 4 years ago · Juan Pablo Isaza Denunciar

0

When you check the typeof all the values then you will get

typeof a => number

typeof b => number

typeof c => object

=== is strict equality, so it will check its type and value

1) If you want to check equality either you can use a == c and b == c .

2) use the valueOf method of c and compare it with a and b as:

a === c.valueOf();
b === c.valueOf();

let a = 3;
let b = Number(3);
let c = new Number(3);

console.log(typeof a === "number"); // true
console.log(typeof b === "number"); // true
console.log(typeof c === "number"); // false
console.log(typeof c === "object"); // true

console.log(a == c);
console.log(b == c);
console.log(a === c);
console.log(b === c);

console.log(a === c.valueOf());
console.log(b === c.valueOf());
/* This is not a part of answer. It is just to give the output full height. So IGNORE IT */
.as-console-wrapper { max-height: 100% !important; top: 0; }

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