Javascript Questions

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

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

A: true false true
B: false false true
C: true false false
D: false true true

Answer: C

new Number() is a built-in function constructor. A…


This content originally appeared on DEV Community and was authored by Esraa

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

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

A: true false true
B: false false true
C: true false false
D: false true true

Answer: C

new Number() is a built-in function constructor. Although it looks like a number, it's not really a number: it has a bunch of extra features and is an object.

When we use the == operator, it only checks whether it has the same value. They both have the value of 3, so it returns true.

However, when we use the === operator, both value and type should be the same. It's not: new Number() is not a number, it's an object. Both return false.


This content originally appeared on DEV Community and was authored by Esraa


Print Share Comment Cite Upload Translate Updates
APA

Esraa | Sciencx (2021-06-23T23:43:36+00:00) Javascript Questions. Retrieved from https://www.scien.cx/2021/06/23/javascript-questions/

MLA
" » Javascript Questions." Esraa | Sciencx - Wednesday June 23, 2021, https://www.scien.cx/2021/06/23/javascript-questions/
HARVARD
Esraa | Sciencx Wednesday June 23, 2021 » Javascript Questions., viewed ,<https://www.scien.cx/2021/06/23/javascript-questions/>
VANCOUVER
Esraa | Sciencx - » Javascript Questions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/23/javascript-questions/
CHICAGO
" » Javascript Questions." Esraa | Sciencx - Accessed . https://www.scien.cx/2021/06/23/javascript-questions/
IEEE
" » Javascript Questions." Esraa | Sciencx [Online]. Available: https://www.scien.cx/2021/06/23/javascript-questions/. [Accessed: ]
rf:citation
» Javascript Questions | Esraa | Sciencx | https://www.scien.cx/2021/06/23/javascript-questions/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.