Skip to main content

Primitive Vs Reference Data Type

 // CLASS TOPICS : Primitive vs reference DATA TYPES   
   
   
 // PRIMITIVE TYPE  
 // x = 10;  
 // y = x;  
 // x = 20;  
 // console.log(x,y);  
 // here x and y both are same but locating different positions in memory and saved at diff places  
   
   
 // REFERENCE TYPE  
 // x = {name:"shagun",email:"abc@gmail.com"};  
 // y = x;  
 // x = {name:"abc"};  
 // console.log(x,y);  
 // both are pointing same location on memory but later on x is pointing a diff location  
   
   
 // REFERENCE TYPE  
 // x = {name:"shagun",email:"abc@gmail.com"};  
 // y = x;  
 // x.name = "testing name";  
 // console.log(x,y);  
 // both are pointing same location on memory. so if one is change other will also reflect the same change  
   
   
   
 // PRIMITIVE TYPES  
 // numbers , string , boolean , null , undefined  
 // REFERENCE TYPES  
 // object , array , functions are reference type  
   
   
   
   
   
   
   
   

Comments

Popular posts from this blog

Spread Operator

// CLASS TOPICS : SPREAD OPERATORS // we cannot sum two array like // array1 = [1,2,3,4,5] // array2 = [6,7,8] // array3 = array1 + array2 // console.log(typeof(array3)); // we will get type string instead of a new array // using spread opearators // array1 = [1,2,3,4,5] // array2 = [6,7,8] // array3 = [...array1,...array2] // console.log(array3) // we can sum up two arrays [...] then array name like array1 and then again ...array2 // to sum up and get a new array with elements of both arrays // using spread operator on object // obj1 = {name:"shagun",age:23} // obj2 = {gender:"male",name:"xyz"} // obj3 = {...obj1,...obj2} // console.log(obj3) // here the only diff is that those properties which are same will get //updated because we cannot have two key

Basics of Object Data Type

// CLASS TOPICS : Object DATA TYPE // myValue = {name:"shagun", age:23,email:"info@codesikho.com"} // console.log(myValue); // object is written using {} symbol // we will write our key:value pair between {} separated by , // value maybe a string , array or a object or maybe a number // HOW TO ACCESS VALUES? // myValue = {name:"shagun", age:23,email:"info@codesikho.com"} // myKeyVal= myValue["email"] // myKeyVal = myValue.age // console.log(myKeyVal); // so we can access either entering key name between [] in a string format // or we can access using . and then key name // we cannot write value with same key otherwise it will get override // myValue = {name:"shagun",name:"abc"} // console.log(myValue.name);

Boolean Data Type

// CLASS TOPICS : BOOLEAN DATA TYPE // true or false // a = 10 // b = 20 // console.log(a != b); // not equal to -> same in javscript is != // equal to => == // we can check logic it will be either true or false // CHAINING LOGIN // console.log(1 > 0 < 5 < 6); // chaining expressions to get logical value either true or false // CHECK IF BOTH ARE TRUE // isBreadAvailable = true // isEggAvailable = false // console.log(isBreadAvailable && isEggAvailable) // so here we are checking if both value are true using && // check if any one of them is true // console.log(1 > 5 || 2 > 5) // using || means you are checking if any of the given condition is true or not // mixup of and ,or // console.log( (1 < 5 && 2 > 5) || 1 > 0)