In ES5, there are five primitive data types:
- object(array is also object)
Before answer the question we should talk about method first.
“Functions define the behavior of an object. When they are part of an object, we call them methods. To call a method on an object, you access the method as though it is a property (it is!), and call it by appending parentheses.”
From the text above we can know, the receiver for a method should be ‘object’. For example we can use array as an receiver and call a
concat() method to merge two arrays.
var array = [1, 2, 3];
array.concat([4, 5, 6]); // [1, 2, 3, 4, 5, 6]
What we can do to test is create a string, check it type, convert it to object, and make it a receiver then invoke the method.
As we can see after we converted the primitive to an object, it should work when we append the
toUpperCase() and call it.
And there is one more thing need to note is, “the string can’t be a primitive and an object at the same time”, only one data type will exist on it at one time.