JavaScript is the language of the original syntax, the logic of which allows you to build dynamic data structures over rigid structures that allow you to optimally solve the problem. Rows are the most important form of data representation. JS offers the programmer convenient functionality for working with strings and the ability to create new string properties.
String - master data
Data and its dimensions are always essential. The master data is the rows. Numbers, booleans, bitmasks, counters, and other, probably appropriate, descriptions of variables have a particular meaning. But the main thing is strings, more precisely objects in general and objects of strings in particular.
Logically, JavaScript string and length (as a property of a string) are not related in any way. Every description description is a string, although according to the formal description:
- var str_1;
- var str_2 = '';
there is no guarantee that the first or second variable is a string. Yes, in the second case, the variable is actually assigned a string value. But, logically, there is no guarantee that str_2 will play the role of a string in the first expression it encounters.
The above example shows how easy it is to calculate the size of the string. Operators:
- str = 123.45;
- str = '' + str;
- alert (str.length) gives the value "6".
In this case, string.length does not directly allow you to get the size of a number as a string of JavaScript. You need to perform an intermediate conversion.
The problem is that numbers in JavaScript occupy an honorable role, proper functional and mathematical objects are allocated for them. But, as a general rule, data transformation is performed automatically, and all that is in this world is strings, including numbers.
Objects and Strings
Formally, a string is an object that has properties. String length is a property of a string object. Not all tasks consider the length of a string to be its real content. For example, a natural language sentence consists of phrases, words, and symbols. Naturally, the desire to determine the sizes in sentences at the level of phrases, words and symbols. At the same time, spaces do not play a role at all.
Writing a string object (meaning a sentence object) is not difficult, and then the length property at the lowest level is the number of characters without spaces. At the level of words, this is the number of words; at the level of phrases, the number of phrases.
Generalizing such objects into a single system, we get a kind of dynamic reference book. JavaScript over length will hang a hidden "tag" about the relevance of this property to the level of nesting and will provide accurate data about the correct number of phrases, words and characters.