When i run this bit of code in Firebug:
var s ="test";
var S=new String(s);
S.len=4;
var t = S.len;
console.log(t);
typeof(S);
S;
It totally omits the output for typeof(S);
But if I do:
var s ="test";
var S=new String(s);
S.len=4;
var t = S.len;
console.log(t);
console.log(typeof(S));
S;
It does just right, what’s going on?
Firebug’s log gives you the result of the last expression (as a debug feature), not each expression. Anything passing
console.log()will of course turn up, and you’ll see this if you doBut it throws in the return value of the last expression and the end, always, but not the preceding ones.
Thus the sequence:
Will yield the return value of
typeof (S);and nothing else and the sequence:Will yield the return value if
S(which is justS). Since the results aren’t stored anywhere in your code it just runs the expression and does away with the result, except in the last expression of any of the above sequences, where Firebug shows you what the result was. This is to facilitate say running a jQuery expression or the like.