comparison bug

Craig shared this problem 7 years ago
Not a Problem

console.log(Int32(5) === Int32(5));

console.log(Int32(5) == Int32(5));

console.log(Int32(5) == 5);


prints


false

false

true


Only the last one makes sense. Help!

Replies (3)

photo
1

looks like if you cast to Number if works...initial tests seem that way:


console.log(Int32(5) === Int32(5));

console.log(Int32(5) == Int32(5));

console.log(Int32(5) == 5);

console.log(Number(Int32(5)) === Number(Int32(5)))


yield:


false

false

true

true

photo
2

Int32(5) is a object. two objects are equal if they refer to the exact same object. please refer to :https://stackoverflow.com/a/6402977


To compare objects, please use ._.isEqual


  1. _.isEqual(Int32(5),Int32(5)) //true

photo
1

Ah. My apologies. Thank you!

Leave a Comment
 
Attach a file