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' ?

type coercion.

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

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -