[Solved] Is there a string increment operator in Javascript? [closed]


It strikes me that this question is a lot trickier than it looked. My immediate thought when reading Zee Tee’s comment that he had written x=+y instead of x+=y was that he (she?) needs better debugging tools. But guess what. I played around with this little test:

/*global console*/
var obj = {"name":"Zee Tee", "id": 1, "location":"Earth"},
prop, s="";
for(prop in obj){
    s += prop + ":" + obj[prop] + " ";
}
console.log(s);

changing += to =+ . I tried it in Aptana and NetBeans 7, both of which normally give me great debugging information and I ran it through JSLint. The two IDEs didn’t signal any error and JSLint offered advice about my for loop but it didn’t identify any problem with the operator. Presumably =+ is valid JavaScript – I just don’t know what it’s supposed to do. This looks like a case of one of those very difficult to trace bugs so typical of JavaScript. Zee Tee, I definitely recommend using IDEs with good error feedback and also using JSLint, but in this case, you tracked down the bug yourself. I wish your question hadn’t got so many downvotes, but maybe if you’d included the code with that bug someone could have tracked it down. You really should answer it yourself with the error you found. I will certainly be checking my typing more carefully in future.

solved Is there a string increment operator in Javascript? [closed]