Array:
In the first case , if you set the length of an array the the array gets padded with undefined . Look at the documentation. Read further
The value of the length property is an integer with a positive sign and a value less than 2 to the 32 power (232).
You can set the length property to truncate an array at any time. When you extend an array by changing its length property, the number of actual elements does not increase; for example, if you set length to 3 when it is currently 2, the array still contains only 2 elements.
And the ECMA Script documentation:
The length property initially has the attributes { [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: false }.
String:
String's length property is read-only . The properties of a string value can not be changed. Look at the ECMA Script documentation:
The number of characters in the String value represented by this String object.
Once a String object is created, this property is unchanging. It has the attributes { [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]: false }.