1

I have a little misunderstanding in JavaScript string type.

According to JavaScript: The Definitive Guide, by David Flanagan,

Any JavaScript value that is not a number, a string, a boolean, or null or undefined is an object. An object (that is, a member of the type object) is a collection of properties where each property has a name and a value

Let's take an example:

var t = "some text";
t.length // give me the length of t

How is it possible? I know that JavaScript strings are primitive values (like numbers), so how is it possible for a primitive value to have a property (like object)?

Oriol
  • 274,082
  • 63
  • 437
  • 513
KarimS
  • 3,812
  • 9
  • 41
  • 64
  • `t.length` under the hood does something like `Object(t).length`, where `Object(t)` is a [string object](http://www.ecma-international.org/ecma-262/5.1/#sec-4.3.18) (not to be confused with a primitive [string value](http://www.ecma-international.org/ecma-262/5.1/#sec-4.3.16)). – Oriol Jun 24 '15 at 22:19
  • Everything in Javascript has a "standard built-in objects", because of it you have a length function in the string object. take a look https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects – danilodeveloper Jun 24 '15 at 22:22

0 Answers0