Primitive data types:
Primitive data type are mainly three types:
Example: – true or false (1 or 0).
Example: – 424, 42.25
Example: – “this is string text”
There are also two primitive data type, which are null and undefined.
Null — if we declare a variable and define the value as “null”, or we want value absolutely nothing in this variable, but we don’t want the variable to be as an undefined.
Undefined — when declare a variable but don’t assign any value in this variable then the value is undefined. When we attempt to call / use this variable it will return “undefined”.
Compound data type:
Compound data are made up with two or more primitive data types. Such as 2 + 2 or 2 + “abs” (hear 2 and abs is two primitive data type that together is compound data type). Array and object are also in compound data types.
var price1 = 44; //number
var price2 = 44.00; //number (decimal)
Both are count as number data type
Var first_name1 = “Osman”; //string
var first_name2 = 2 + “Osman”; //string
var first_name3 = 2 + 4 + “Osman”; //string
var first_name4 = “Osman” + 2 + 4 ; //string
We can use same variable as different data type dynamically, Like:
var sam; //undifined
var sam = 44; //number
var sam = 44.22; //number
var sam = “strin”; //String
Declares / creates an array, variable are containing three value into a single variable.
var arr = [“abc”, “def”, “ghi”] //declare array with value
var arr = new array(“abc”, “def”, “ghi”) //another declare array with value
arr = “abc”;
arr = “def”;
arr = “ghi”;
Comments are closed.