|0) is used to force JS to convert to int32, it can be ommited from both examples and it will run too.
xsum*(((xsum>0)<<1)-1)
one multiply one sub one shift one compare. In C code there are faster bithacks to get abs value, like (x ^ (x >> 31)) - (x >> 31) for ints
but this works for anything and not arch-specific.