Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

326
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda