4

JavaScript strings are immutable. This means that once a string is created, it is not possible to modify it. However, it is still possible to create another string based on an operation on the original string

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures

I understand what immutable mean, but i need to know why they built it like this and what the value of this immutable approach?

Note: I reviewed some Java reference but I'm not Java developer, and I can't understand there terms (StringPool, hashcode ...)

Community
  • 1
  • 1
jobin
  • 1,097
  • 2
  • 9
  • 21
  • 3
    Did you [confuse Java & Javascript](http://stackoverflow.com/questions/245062/whats-the-difference-between-javascript-and-java)? Related: [Are JavaScript strings immutable? Do I need a “string builder” in JavaScript?](http://stackoverflow.com/questions/51185/are-javascript-strings-immutable-do-i-need-a-string-builder-in-javascript) – Huey May 04 '15 at 06:10
  • They should start emphasizing more on ECMA instead of JavaScript... – Mr. Alien May 04 '15 at 06:13
  • I'm not confuse between java and JavaScript, I'm asking about something in JavaScript, have similarity with something with java. and I need help to answer this question based on JavaScript terms. thank you – jobin May 04 '15 at 06:15
  • Might be a re-post have you taken a look at this answer ? http://stackoverflow.com/questions/51185/are-javascript-strings-immutable-do-i-need-a-string-builder-in-javascript – Shenal Silva May 04 '15 at 06:15
  • @ShenalSilva thank you, I understand what is immutable. but I need to know what is the benefits. – jobin May 04 '15 at 06:17
  • "put on hold as primarily opinion-based by@Jens, Terry, Bohuslav Burghardt, torazaburo, Willie Wheeler 2 mins ago" I'm asking about fact, they built it like this then there is reason for that, and should be good reason because most languages use this approach with strings. – jobin May 04 '15 at 06:22
  • @Terry why this question "http://stackoverflow.com/questions/2068804/why-is-string-class-declared-final-in-java" did not put on hold as primarily opinion-based. I need to fix my question if I ask it in wrong way. – jobin May 04 '15 at 06:30
  • Good answeres in [Why are strings immutable in many programming languages?](http://stackoverflow.com/questions/9544182/why-are-strings-immutable-in-many-programming-languages) – try-catch-finally Jan 22 '17 at 15:06

0 Answers0