Is there a shorter way to write this?
var ttt = "dd";
if (ttt.length < 3)
ttt= "i" + ttt;
Is there a shorter way to write this?
var ttt = "dd";
if (ttt.length < 3)
ttt= "i" + ttt;
Yours is pretty short, but if you want to use the the conditional operator (a.k.a the ternary operator), you could do the following:
var ttt = "dd";
ttt = ttt.length < 3 ? "i" + ttt : ttt;
... or if bytes are really precious (code golfing?), you could also do something like this:
var ttt = "dd".length < 3 ? "i" + "dd" : "dd";
... but then that could be reduced to just:
var ttt = "idd";
... as @Nick Craver suggested in a comment below.
var ttt = "idd"; seems pretty short ;) Also, you need quotes around the i to be 100% on this one ;)