When are values copied?
<p>I know Javascript always passes objects by reference.  But what about the other types?</p>

<p>number - ?<br />
string - Immuteable, so it shouldn't matter<br />
object - ref<br />
array - ?<br />
function - ?<br />
regexp - ?<br /></p>

<p>I came to the conclusion that not all values in Javascript can be objects nor can they be pass by reference with the <a href="http://jsfiddle.net/smacky311/7hh6C/9/" rel="nofollow">following code</a>:</p>

<pre><code>function SomeFunc(func) {
    var numba = 0;
    var innerFunc = function() {
       numba = func(numba);//try commenting me out and switching to next line
        //func(numba);//numba fails to increment
       return numba;
    };
   return innerFunc;
}

//this variable should persist the numba variable through closure.  Incrementing each call by 1.
var closure = SomeFunc(function(numba) {
    numba = numba + 1;
    return numba;
});

document.writeln(closure());
document.writeln(closure());
document.writeln(closure());
</code></pre>

<p>Because <code>numba</code> fails to increment, unless I return the number and updated the variable in closure...then that tells me this is not pass by reference.  Am I missing something?</p>

<p><hr />
or take the very basic </p>

<pre><code>function UpdateNumber(numba) {
    numba = 10;  
   document.writeln('in func number becomes ' + numba);
}

var numba2 = 5;
UpdateNumber(numba2);

document.writeln('back to caller number is ' + numba2);
//in func number becomes 10 
//back to caller number is 5 
</code></pre>
