1

Arrays are mutable. I can do this:

var arr = [0,1,2,3];

arr[4] = 4;

but not this

var str = "abcd";

str[4] = "e";

This is something I don't find intuitive.

nativist.bill.cutting
  • 1,292
  • 3
  • 11
  • 19
  • 4
    See http://stackoverflow.com/questions/9544182/why-are-strings-immutable-in-many-programming-languages – siledh Oct 01 '13 at 12:26
  • 2
    The real question would be: why on earth are C strings mutable? – Stefano Sanfilippo Oct 01 '13 at 12:26
  • The duplicate Q/A is very one sided. If it was 100% correct than language designers would make more things immutable. – nativist.bill.cutting Oct 01 '13 at 12:31
  • 1
    @StefanoSanfilippo I think the OPs question is valid. To answer yours, because RAM is mutable: you *initially* get the ability to change whatever you want at the lowest level. It's when you want some features at a higher level that you first want something immutable. Thanks for the link @siledh! – jozxyqk Oct 01 '13 at 12:38
  • yea don't forget that software doesn't live in a cloud with fairies and elves, it lives in real hardware. – nativist.bill.cutting Oct 01 '13 at 12:45

0 Answers0