I was under the impression that strings have properties, such as match. Why does console.dir('') claim that '' has no properties (at least in Google Chrome)?
I was under the impression that strings have properties, such as match . Why
Share
It’s because
''is a string literal, not an instance of theString“class”. As properties likematchare declared onString.prototype, you won’t see them when using a string literal. If you use thenewoperator you will see what you expected:Here’s a screenshot from Chrome’s developer tools (notice the need to expand the
prototype, as the method you’re expecting to see is declared on the prototype, not theStringobject itself):