Semicolon is optional, but you should use it!
Basically you are wondering what is in the black box.
By default the sort method is set you to compare strings. So if you were to sort that number without the custom function it would return a funny result. Hence why you probably found this code.
Now with this code you are passing a reference to a funciton that is doing subtraction. Now as explained this subtraction is used to do a comparsion. A positive number, negative number, and zero tells the hidden part of the code what is going on for the sort.
Now when we add this reference to a function, we are passing the instructions to the hidden code we do not see. What is going on in the back ground is this (this is a basic idea, not the exact thing!)
return a - b
//fancy way to extend the Array Object (normally you do not overwrite methods that exist!)
Array.prototype.sort = function(fnc)
var _arrOrg = this; //The orginal array that is sent in.
var _arrNew = new Array(_arrOrg); //Create a new array to insert the new values
for(var i=1;i<_arrOrg.length;i++) //loop through the orginal array to get the values
var _inserted = false; //set a flag so we know if we got a match
for(var j=0; j< _arrNew.length;j++)//loop through the values of our new array
var _comp = fnc(_arrOrg[i],_arrNew[j]); //use the custom function specified by the user sending the orginal array value we need to find a new home and the new array we are now sorting
if(_comp<0) //if it is less than the current value
var x0 = _arrNew.splice(j,0,_arrOrg[i]); //add it to the new location
_inserted = true; //set the flag to true
break; //exit this loop since we found the spot
if(!_inserted)_arrNew[_arrNew.length] = _arrOrg[i]; //make sure we found the spot, if not add it to the end of our new array
return _arrNew; //return the newly sorted array back
var arr = new Array(6);
arr = "10";
arr = "5";
arr = "40";
arr = "25";
arr = "1000";
arr = "1";
document.write(arr + "<br />");
Hopefully that shows you what is happening inside that black box a little bit.