So I will try write and share those part, but if you guys find something loop please feel free to give any comment!!
- Object 2. Program Structure 3. Functions 4. Bugs and Error Handling
object type: function, arrays, key/value, data structure (like json) , and + Primitive type: Number, String, Boolean,
this is the Primitive type get the object treatment sample, Primitive get wrapped with an object temporarily, so this method will give properties new value: example.com, but just for use once, the subsequent to access new property will fail!
So remind also the object never comparable unless transfer back to Primitive type
Next Example is set variable value are User’s define type or jquery object, then we could not compare as result is always false:
For example here, make 2 variable as object, so two object is incomparable! Even add valueOf method!
And here add toString method, then compare as string length, since it’s back to compare with Primitive type, so the result is true, meanwhile, as compare as object, the result is always false!!
In this case, we play around with valueOf method, then compare this object with function, then back to compare as object, then it’s become comparable!! it’s because the method transfer those object value as Primitive Type, so now we could compare now!!
And not only Number, String could compare, we could also compare boolean also, this is example we compare use valueOf method, so we could also see the result comparable as true or false!
Hers is for Arrary object, as for sort method, we could only get result [3,7,2,9,1,4,8], so it has use callback to put in sort method to compare between 2 numbers, then we could get the result we want.