1

I have studied about primitive data and complex data in w3schools. I searched elsewhere as well, but they don't give sense for me.The sentence stated below defines a primitive data.

A primitive data value is a single data value with no additional properties and methods.

It explicitly says that they don't have properties and methods. However, Primitive data types like string, number have properties and methods. which in turn it is refuting its own definition. Please help me figure out what are primitive data and complex data and what are the difference between them in Javascript?

Edit: a method of string is str.indexOf("abc") and its property str.length. Still they have properties and methods

  • 1
    No, a primitive value does not have properties - try to assign one! When you access properties on them, they get *wrapped* in an object that will let them inherit from prototype objects. – Bergi Oct 17 '18 at 11:27
  • Try a better resource methinks: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures – Liam Oct 17 '18 at 11:27

0 Answers0