First of all, there is a typo, it should be "雷一" should be "another", and "wear piece" should be "create".
He was not very clear when describing this paragraph. In fact, all his descriptions here are based on the memory space, that is to say:
In JS, the memory space of a string cannot be modified directly once it is created. If you need to change the value of a variable, you must first destroy the originally allocated memory space, reallocate the memory space and fill it with a new value.
So, his explanation of the code refers to var lang = 'java'This creates a string value, and the memory space corresponding to this value cannot be changed, lang = lang + 'script'When the value is reassigned here The operation is:
First open up a new memory space of 10 characters
Fill the original lang value memory space and the 'script'string memory space correspondingly into this 10-character memory space
Destroy the two spaces that originally stored lang and 'script'strings
Assign the newly opened and filled space of 10 characters to the variablelang
If your understanding is based on the appearance you can see (such as string variables and the like), then you must have been fooled by the author's excessive omissions.
First of all, there is a typo, it should be "雷一" should be "another", and "wear piece" should be "create".
He was not very clear when describing this paragraph. In fact, all his descriptions here are based on the memory space, that is to say:
In JS, the memory space of a string cannot be modified directly once it is created. If you need to change the value of a variable, you must first destroy the originally allocated memory space, reallocate the memory space and fill it with a new value.
So, his explanation of the code refers to
var lang = 'java'
This creates a string value, and the memory space corresponding to this value cannot be changed,lang = lang + 'script'
When the value is reassigned here The operation is:First open up a new memory space of 10 characters
Fill the original
lang
value memory space and the'script'
string memory space correspondingly into this 10-character memory spaceDestroy the two spaces that originally stored
lang
and'script'
stringsAssign the newly opened and filled space of 10 characters to the variable
lang
If your understanding is based on the appearance you can see (such as string variables and the like), then you must have been fooled by the author's excessive omissions.