Data-Types in JavaScript (Primitive and Reference) with Examples

Data types are of 2 types-

  1. Primitive data-type
  2. Reference data-type

A Primitive data-type is not an object and it has no methods. Primitive data-types are base data-type.

A Reference data-types are objects and arrays (technically one, since arrays are objects). When you creates an object, that value is not directly assigned to the variable and these are objects type.

There are some Primitive Data-Types-

  1. String
  2. Number
  3. Boolean
  4. Null
  5. Undefined
  6. Symbol

Let's understand these data-types one by one

  • Strings - Strings are the collection of characters and are inside inverted commas e.i., ( " " - double inverted commas ) , ( ' ' - single inverted commas) and ( ``- backticks)

string.png

stringch.png

  • Numbers - Numbers are numerical digits that are represented without any inverted commas, unless they will become a string.

numbers.png

numberch.PNG

  • Boolean - Boolean are true and false, in other words, the value of boolean datatype is always true or false.

boolean.png booleanch.PNG

  • Null - Null are an intensional empty value, we use null for the condition when we have to check it later that does its value is null or not

ull.png ullch.PNG

  • Undefined - Undefined are the default values of a variable we have declared but doesn't define its value

undefined.png undefinedch.PNG

There are some Reference Data-Types-

  1. Arrays
  2. Object-literals
  3. Functions
  4. Dates

Let's understand these data-types one by one

  • Arrays - Arrays are a single variable that is used to store different values. These are an ordered list of values. Each value is called an element specified by an index.

array.png

arraych.png

  • Object - An object is a standalone entity, with properties and type.

object literals.png

object literalsch.png

  • Functions - These are a set of statements that performs a task or calculates a value, but for a procedure to qualify as a function, it should take some input and return an output where there is some obvious relationship between the input and the output.

functions.png

functionsch.png

  • Dates - Date objects represent a single moment in time in a platform-independent format. Date objects contain a Number that represents milliseconds since 1 January 1970 UTC.

dates.png

datesch.PNG

Thanks for reading. If you have any query or doubts, feel free to ping me on twitter- (twitter.com/Krishn_aGupta)

That was JavaScript Data-Types, If you have any feedback then you can share it in the comment below. Also, if you find it useful, please like and hit that follow button.

Stay tuned for the next article:)