I want to share this post cause first my JavaScript is so bed that I think I should re view again form the beginner path,  and might be loop some important keys, just want share some points that I got confused a lot during developing process!

So I will try write and share those part, but if you guys find something loop please feel free to give any comment!!

  1. Object 2. Program Structure 3. Functions 4. Bugs and Error Handling


Today want to share javascript Object, as simple start, Object could be:

object type: function, arrays, key/value, data structure (like json) , and + Primitive type: Number, String, Boolean,null, undefined 

for example:

Capturethis 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

for example:


Here I give a1 variable value “tess”, and give  a2  as new object which are Primitive type, then typeof a1 and a2 is different, but as compare both, it’s ture as result! here we could find javascript will transfer the Type first for us, then compare the value after

Next Example is set variable value  are User’s define type or jquery object, then we could not compare as result is always false:

1 2

so in javaScript, all the Object not equal , event add valueOf or toString method, not doing the equal compare math.


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.

So this part Conclusion is as Object in javascript, it’s never comparable as back to Primitive Type, and in order to transfer to Primitive type, we need the valueOf/ stringOf method to help us get Primitve type then go to compare path!

Next: Prototypes


Leave a comment

Leave a comment

Your email address will not be published. Required fields are marked *