Answer the question
In order to leave comments, you need to log in
A string in JS is not an object, why does it have properties and methods?
I'm learning JS from scratch, help dispel some misunderstandings.
A string in JS is not an object, why does it have properties (str.length) and methods (str.charAt(pos))?
Aren't properties and methods unique to objects?
obj = {
properties: 'some properties',
method : someMethod()
}
Answer the question
In order to leave comments, you need to log in
And what worries you? This is a counter.
www.ixbt.com/storage/hdd-smart-testing.shtml
When accessing the properties of primitives, a temporary object of the corresponding type is created and its property/method is called. (For sure, in engines everything is much more complicated and there are a lot of optimizations, but from the point of view of use it doesn’t matter)
> And how, in this case, to distinguish between properties and methods in general
No way. Methods are just function properties.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question