What does it mean by an instance of a data type?

@object4182780719 you’re welcome :slightly_smiling_face:

so brilliant explaination. thank u so much :heart_eyes:

1 Like

@extraordinaryalexia6 you’re welcome

Thanks, this simple explanation broke it down for me.
Cheers!

1 Like

wow! thank you so much for this explanation

1 Like

I love your explaination!!! so clearly and easy to understand in my real life experience. :slight_smile:

1 Like

this really helped me out. this is the power of internet!

1 Like

Hi, best explanation for me :smiley:

But, can I say that Instance are some kind of sub-type of data types? I mean, there’s a way I can imagine in my mind. you talk about:

@joseulisesjuarezparr saying “sub-type” may be a bit confusing, I prefer to say something like : “Jose” can be CLASSIFIED under string data type. But let me just give an example to further explain,

Let us say we have an Aeroplanes object and a cars object.

Instances of the Aeroplanes object include: Airbus A320 , Boeing 737- max.
Now the vehicles which are classified as Aeroplanes are instances of the Aeroplane object and therefore have properties and methods of the Aeroplane object.

some of the properties could be:
wingLength, numberOfEngines, seatingCapacity.

some of the methods could be:
takeOff( ), land( ), elevate( )

This means that any vehicle classified as an aeroplane would have these properties and would perform this functions or methods.

Instances of the cars object include: Toyata Camry and Kia Cerato.
some properties could be:
sizeOfBonnet, sizeOfTrunk, seatingCapacity, color, fourWheeldrive etc

some methods could be:
drift( ) ,start( ), park ( ), accelerate ( ), reverse( ), overtake( ) etc

This means that any vehicle classified as a car will have these properties and methods.

Now relating this to programming.
when we type “Hello world”, in Javascript, it is classified as a string and is therefore an instance of the string data type, this means it would have properties and methods of the string object.
This means we can use a property like .length on a string and a method like .split( ).

When we type 19 it is classified as a number and thus is an instance of the Number data type. This means that it would have properties and methods of the Number object.

It is important to know what data type you are working with so we know the right properties and methods to use.
Just like it would be crazy for a pilot to try to .drift( ) with a boeing 737-max or a driver try to do .takeoff( ) with a car, because only instances of cars can drift and only instances of aeroplanes can fly.
This would be like using .length and .split( ) on a Number data type when they should be used for a string data type

I hope this clarifies any confusion :slightly_smiling_face:

4 Likes

Thank you very much!! :heart_eyes: for taking the time to write your answer in such detail. Everything is much clearer to me. :raised_hands:

Again, thank you very much. :smiley:

1 Like

you’re welcome, happy coding. :slightly_smiling_face:

You will be a good teacher

1 Like

Phenomenal explanation!!

1 Like

6 posts were split to a new topic: Link is not working