What are data types?

data type is a classification of data which tells the compiler how the programmer intends to use the data.

Think of this as you telling your computer how it should use the information you give it. For example if you want to add to number you have to tell your computer you’re using numbers. Then it would know “oh these are numbers”, I can add or even subtract these.

JavaScript has six data types, five primitives and an object

What is a primitive?

A primitive is a value that cannot be changed.  Think of these are a really long list of accepted values understood by your computer. i.e 1, 2, true, false, “a”, “b”,”cow”, “dog”, the list goes on. Think a really really really big dictionary.

  • Data Types:
    • Boolean (P)
        • This can only be true or false
        • Think yes or no
          var isOld = false;

       

    • Null  (P)
        • A pointer/reference to nothing or an empty space
        • Think of this as having an empty parking space. There’s lines that show you can park there but if there’s no car there then we’d say the parking space is null. You know you have something but it’s empty
          var parkingSpace = null;

       

    • Undefined  (P)
        • A value that hasn’t be set yet
        • Think of this as not being unknown.
          var whoAmI;

       

    • Number  (P)
        • This is exactly what you’re familiar with. A symbol used to represent the count of something: 1,2,3, 5.4, 1000, etc
          var digit = 7;

       

    • String  (P)
        • A letter, word phrase or sentence
          var str =  "Programming is easy";

       

    • Symbol ( P)
        • A one of a kind name you can use an identifier
        • Think of this as your social security number. Everyone has one and no two are the same
          var ssn = Symbol("123-34-1234");

       

    • Object
        • Everything else not described above.
        • Think of this as a way to describe something but you can only do it with using types and items the computer will understand. Say you want to make a toy object. You have to describe it is a way the computer will understand it using properties such as number of wheels it has (Number), the color (String) , does it talk (Boolean)  etc
          var toy =  {"doesTalk": false, "numberOfWheels": 0, "color": "pink"};

           

If you like this article or would like a specific topic explained drop and comment below. I would love to hear your feedback!

Leave a comment

Your email address will not be published. Required fields are marked *