More efficient version of an ID calculator in JavaScript
Here's a better implementation.

Used the unary + operator for number conversion.

Used null instead of undefined since it's shorter and produces the same result because of type coersion.

Avoid performing a substring operation by starting to iterate from index 4.

Cached num.length into len so that we save on property lookups when the condition is evaluated for every loop iteration.

Removed uneeded parenthesis.

Took advantage of the += operator.

Made sure that every variables were locally scoped. The _local1 variable in the selected answer isin't properly scoped.

Used a single var statement; it's a better practice to declare variables at the top of the function for readability.

Stole the % 10 idea from the other answer since I thought it was great ;)

 function getidnumber (num, ts) {
    var i = 4, 
        len = num.length,
        res = '@user';

    ts = ts == null? '3452' : ts;

    for (; i &lt; len; i++) {
        res += (+num[i] + +ts[i - 4]) % 10;
    }

    return res;
}