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

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

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 Report

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 Report

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 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!