๐ JavaScript: Array's length vs String's length
-
โฉ
โ Introduction
In JavaScript,
โง Array is an Object whereas String is a primitive
โง Despite String being a primitive, for easy operations it has a lot of methods and, properties
โง String is considered as Array-Like
โง Both Array and, String has a "length" property
โ Array's length
โง Unlike many other languages, JavaScript actually allows to modify an array's length manually.
โง If we set a larger length, few blank spaces (holes) are added to the end.
โง If we set a smaller length, elements are removed from the end.
โ String's length
โง String is immutable. Hence, in no way we could modify a String.
โง String's length property is that's why immutable.
โง When we try to set a new length, the operation is ignored.
โ Final Words
โง In JavaScript, Array's length property is allowed to modify manually. Either array is expanded or, truncated towards its end-side when we modify its length.
โง In JavaScript, String is immutable and thus its length property as well. It can't be modified.
๐ญ Feedbacks
โง Did you find this thread useful?
โง After reading through entire thread, have you learnt something worth?
โง What improvements will you suggest?
Hey ๐. I will be happy to hear from you. Your feedbacks would help me sharing better contents in future.
End of ๐งต
Hey ๐ I am a Tech Educator from India ๐ฎ๐ณ
I am sharing Tutorials, Tips, Techniques, Infographics, Cheat Sheets, Interview Questions and Roadmaps on Web Development, DSA and, Database.
Are you interested? I am sure, you are.
To never miss anything, Follow Me โ
โข โข โข
Missing some Tweet in this thread? You can try to
force a refresh