primitive data types and wrapper objects(type conversion) | Sololearn: Learn to code for FREE!


primitive data types and wrapper objects(type conversion)

Is what I'm saying correct? string, number, object, function, symbol,etc, are primitive data types.(objects are String Number, Date, Object,etc)when we use them as object they convert to object automatically example: (2.9).toFixed()//this number convert to Number object. There is an exception here that function are actually objects. try this : function f(a) { return a; } var b=new f(function () {}) console.log (typeof b) // function result is function. while if we pass an non-function type to this object-constructor, result is object.What other reason could it have been other than that the functions are callable objects?

4/14/2021 7:16:18 PM

Mehran [Inactive]

4 Answers

New Answer


You got some of the primitives correct but function and object incorrect. Here's the full list of 7 with their corresponding wrapper objects in brackets: string (String) number (Number) boolean (Boolean) symbol (Symbol) bigint (BigInt) undefined null Primitives don't have methods. You're right to say they get converted to the corresponding wrapper objects to allow you to call methods. One thing to note is that once you're finished with the wrapper object, it's removed. So, you're left with a primitive again. So, we've touched on primitive types. The other major category is object types (also called reference types). There are 3: Object, Array, and Function. So yes, functions are objects. More specifically, they are callable objects as you correctly say. They are also first-class objects, which means they can have methods and properties and methods just like any other object. Examples showing the length property and toString() method of Function objects: const f = (x) => {} console.log(f.length) // 1 const g = () => {} console.log(g.toString()) // "() => {}"


CamelBeatsSnake ok, I ignored some primitive types like bigint


there is very interesting answer


Thanks for the information you shared. Loved the way you explained everything in this blog.