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)?
It's because ''
is a string literal, not an instance of the String
"class". As properties like match
are declared on String.prototype
, you won't see them when using a string literal. If you use the new
operator you will see what you expected:
var s = new String("hello");
console.dir(s);
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 the String
object itself):
Likely for the same reason that console.dir(true) and console.dir(1234) say that once you turn down the knob pointing to the data. It's likely the code only iterates through properties if it's an Object. Why that turndown knob is still there is unclear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With