DEV Community

Himanshupal0001
Himanshupal0001

Posted on

Starting Vanila Js as a noob....if you want get along on this journy. (2nd day)

Hello folks,So today we gonna talk about datatypes. But first you need to know about variables. Don't need to worry I've got your back. Here's the link .

Now what is datatypes you might ask. Or....may be not!! anyways

Image description
Datatypes are nothing but pronunciation for a particular set of data.I put this in simple way... what you call a round object?
Obviously a circle right. It doesn't matter that object is real or virtual, what type of material it has or made of if you see a round object it is circle.

Datatypes act as same. For example string="anything put in colons is string". As you see datatypes follow a structure that gives them a particular structure to identify data.

There are two types of datatypes in Js.

  1. Primitive
  2. Reference
// Datatypes are the keywords used in any programming language
//which define a particular set of value.

//There are two types of datatypes
//1. Primitive
//2. Reffrence 

//Primitive data types are already given in js which are:-
// String, Number, boolean, Null, Undefined, Symbol(new in ES6)

// String anything put between ('') or ("") are strings
let name="Himanshu"
console.log("My string is :" +name);
console.log("My datatype is: " + (typeof name));

// Numbers

let marks = 35;
console.log(" Data type is: " + (typeof marks));

//Boolean

let isDriver = true;
console.log("Data type is: " + (typeof isDriver));

//Null

let nullVar = null;
console.log("Data type is: "+ (typeof nullVar));

//undefined

let undef;
console.log("Data type is :" +(typeof undef));

//Reffrence datatype

//arrays
let arr = [23,43,56,43,56, false, "string"];
console.log("Data type is :"+ (typeof arr));

//Object Literals

let stuMarks = {
    Himanshu: 89,
    satya: 87,
    Mark: 84
    //if you put
    //Jason lee: 80 it will throw an error
    //instead you can use 'Jason lee': 80
}
console.log(typeof stuMarks);

//function
function fName()
{}

console.log(typeof fName);

//Date

let date = new Date();
console.log(typeof date);
Enter fullscreen mode Exit fullscreen mode

Primitive data type

Primitive datatypes are built in datatypes in any language.
Primitive data types in Js are:

  1. String
  2. Number
  3. Boolean
  4. Null
  5. Undefined
  6. Symbol (new in ES6 will talk later)

As you can see in the code block there are example for each data type. You can understand by example what type of datatypes except what types of value.

Reference data type

Sometime primitive data types re not enough to represent the data or to solve a problem. So we use reference data type which is an object data type. We'll talk about object in next post. But for now all you need to know that we can mold these data types according to our need and use it in code.

Reference data types in Js are:

  1. Arrays
  2. Function
  3. Date
  4. Classes (may be let me know in comments)

Also example given in code block.
Let me know your suggestions in comment box. Feel free to criticize.

I am waiting 0_0

Image description

Top comments (1)

Collapse
 
kcubeterm profile image
Krishna Kanhaiya

i will suggest you this playlist ( Namaste javascript) https://www.youtube.com/watch?v=pN6jk0uUrD8&list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP

and for more deep knowledge you should read "you dont know javascript' book series