Strings in javascript

I recently saw some links that explain Strings in Javascript as a primitive type. I know that a primitive is a data type that does not consist of other data types and cannot be further broken down. But the problem is that I also read the lines - objects. How can it be? Please clarify to me about the confusion.

+4
source share
1 answer

You can read about this exact topic in MDN:

Note that JavaScript distinguishes between String objects and primitive string values. (The same is true for booleans and numbers.)

String literals (indicated by double or single quotes) and strings returned from String calls in the context of a non-constructor (that is, without using a new keyword) are primitive strings. JavaScript automatically converts the primitives to String objects so that String Methods can be used for primitive strings. In the context where the method is to be called in a primitive string or property search, JavaScript will automatically wrap the string primitive and call the method or perform a property search.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

+3
source

Source: https://habr.com/ru/post/1496356/


All Articles