JavaScript Object Literal Evaluation and valueOf -
how following code segment evaluates 0.25 ? don't understand how object literals working.
({valueof: function() { return 1}} / 4)
all others below evaluate nan:
({prop1: function() { return 1}} / 4) ({valueof: 1} / 4) ({valueof: "1"} / 4)
also there special have property named 'valueof' ?
if call
21 + "21" // "2121"
javascript implicitly coercing number string calling tostring()
on it.
similarly, in example, javascript implicitly coercing object number calling valueof()
.
Comments
Post a Comment