The last thing I recall biting me in JS and I didn't see it mentioned above:
3===newNumber(3)// false3===Number(3)// true
The first one is false because new creates a Number object instance which is compared by reference. Value does not equal object reference.
typeofnewNumber(3)// object
The second one is true because it is a function which returns a value type.
typeofNumber(3)// numbertypeof3// number
This is a Javascript feature that is best avoided.
Type coercion is one of the worst parts of JS. I could not even count the number of hours I have wasted tracking down bugs because of this "feature". It is one of the main reasons I avoid the language.
The last thing I recall biting me in JS and I didn't see it mentioned above:
The first one is false because
new
creates a Number object instance which is compared by reference. Value does not equal object reference.The second one is true because it is a function which returns a value type.
Type coercion is one of the worst parts of JS. I could not even count the number of hours I have wasted tracking down bugs because of this "feature". It is one of the main reasons I avoid the language.
Yeah, object wrappers. They almost never have an advantage over the normal primitives.
Those sort of bugs can truly be frustrating.