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

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -