O
O
Ord EO2019-02-11 14:14:03
Solid State Drives
Ord EO, 2019-02-11 14:14:03

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()
}

And how in that case generally to distinguish properties and methods?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
Cole, 2016-08-02
@dQw4w9WgXcQ

And what worries you? This is a counter.
www.ixbt.com/storage/hdd-smart-testing.shtml

L
Lynn "Coffee Man", 2019-02-11
@OrdeO

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 question

Ask a Question

731 491 924 answers to any question