I have been reading here
https://developer.mozilla.org/en-US/docs/JavaScript/Memory_Management#Allocation_via_function_calls
and these lines confused me a bit:
var s = "azerty";
var s2 = s.substr(0, 3); // s2 is a new string
// Since strings are immutable value, JavaScript may decide
// to not allocate memory, but just store the [0, 3] range.
So the comments say, JavaScript may decide to not allocate memory and just store the range [0,3] , Now doesnt memory have to be allocated before storing? in case not, as the comment implies, what exactly happens so that the stored range, gets stored in free space, not occupied already by other values.