Howdy all. I’m trying to grasp the basic behaviors of operators and whatnot. The referential and structural equality makes perfect sense, but when applying less-than and greater-than to data structures leads to some behavior that I don’t understand.
let obj0 : School.person = {
name: "Dave",
age: 20
}
let obj1 : School.person = {
name: "Bill",
age: 25
}
let obj2 : School.person = {
name: "Bill",
age: 25
}
obj0 > obj1 // Evaluates to true
I’ve been playing around with the values and can cause the comparison to evaluate to false by changing the name fields to different strings. For example, changing “Bill” to “S” results in false. If I keep the names unchanged, no matter the size of the age field of obj1, it remains true.
obj1 > obj2 // Evaluates to false
Identical objects results in false, which makes sense. And if I change the age of Obj1 to 26, then it evaluates to true, indicating that the compiler is indeed trying to coerce some sort of numeric value from the structures for the sake of the comparison. This also indicates that using the > and < operators will trigger a structural comparison.
I’m assuming that the comparison starts comparing from the top of each object and reaches a conclusion as soon as a field is found to be different, but how does it coerce a numeric value from a string?