Why obj[-0] not equal to obj['-0'] in JavaScript -


in javascript

var obj = {   '34': 'i 34',   '-777': 'i -777',   '0': 'i 0' } obj[34]   // 'i 34' obj[-777] // 'i -777' obj[0]    // 'i 0' 

it seems obj[number] equal obj[number.tostring()]. comes different -0 , +0:

var obj = {   '-0': '-0 here',   '+0': '+0 here' } obj[+0]; // undefined obj['+0']; // '-0 here'  obj['0'] = 'just 0'; obj[+0]; // 'just 0' obj[-0]; // 'just 0' 

why?

it seems obj[number] equal obj[number.tostring()].

yes. in ecmascript 5, properties have property names strings - , whatever pass property access operator (bracket notation) implicitly cast string.

but comes different -0 , +0

no, it's same those. seem confused fact both string(-0) , string(+0) yield "0", that's how is.


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -