In JavaScript, strings are immutable. That means any operation on them returns a new object. Methods like trim, replace and slice don't modify the existing string.
However, I was playing around in jsconsole and found an exception
string = "string";
string + 37;
=> "string37"
string;
=> "string"
The original string hadn't changed here. Here's what happens when I apply the increment operator on the string. Here I am expecting to see string returned.
string++;
=> NaN
string
=> NaN
I was trying to see whether this would return strinh, like it would in some other languages.
Regardless of whether string++ would work, it shouldn't modify existing string objects. Yet it did just that. Does anyone know why?