Skip to main content

Posts

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
Recent posts

Method of Array Data Type

// CLASS TOPICS : FEW METHOD OF Array DATA TYPES // reverse // list = ["a","b","c","d"].reverse(); // console.log(list); // it will reverse the array whether it is array of string, number whatever // Pop // list = [1,2,3,4]; // list.pop(); // console.log(list); // it will remove the last element from array // why we are writing .pop in next line? // because pop will remove last element from orignal array it is going to return only the elemet it is removing not a new array. // if we write list = [1,2,3,4].pop() then as i said it will return last element that is 4 // Slice // list = [1,2,3,4,5].slice(0,4) // console.log(list); // same as in string // To string // list = [1,2,3,4].toString() // console.log(list,typeof(list)); // convert array to a string // Concat // list = [1,2,3,4,5].concat(["a","B","c"],[

Method of String Data Type

// CLASS TOPICS : FEW METHOD OF DATA TYPES // TO LOWER CASE // myVal = "HELLO".toLowerCase() // console.log(myVal); // it will convert whole string to lowercase like "hello" // TO UPPER CASE // myVal = "hello" // myVal2 = myVal.toUpperCase() // console.log(myVal2) // it will convert whole string to uppercase like "HELLO" // REPLACE // myVal = "hello".replace("ll","b") // console.log(myVal); // it will replace some part of string to something else // here it will replace ll to b // SPLIT // myVal = "hello".split("e") // console.log(myVal); // it will split the string in diffrent part acc to the charac you have passed // SUBSTRING // myVal = "hello".substr(0,2) // console.log(myVal); // it will return substring first value you are passing to substr is // a index from where you want to start // and second value that you passing is length of string that you need // TRIM // m

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);

Basics of String Data Type

// CLASS TOPICS : STRING DATA TYPE // "H" , "E" , "L", "O" // string is a combination of few characters // we can re-assign variables as done below // myValue = 'hello' // console.log(myValue, 'called') // myValue = 1 // console.log(myValue, 'called 2') // myValue = [1,2,3] // console.log(myValue,'called 3') // we can access charac from string same as we can do with array's // myValue = "hello" // myCharac = myValue[2] // console.log(myCharac); // we can create space b/w charac too // myValue = "hello " + "world" // console.log(myValue) // behind the scenes space is also being stored like this: ["h","e","l","l","o",""] // we can use \n to print data in next line // myValue = "hello my name is: \n shagun" // console.log(myValue); // we can also use \t to create space between words in the same line

Array Data Type

// CLASS TOPICS : ARRAY DATA TYPE // myList = [10,15,20,-1]; // array is defined by using symbol [] // console.log(myList) // how data is stored in a array // myList = [1,2,3,4,5]; //[0index -> 1, 1-> 2,2 index -> 3 ] // myValue = myList[1] // using [] and entering a index b/w []. we can get the value which is stored at that particular index // console.log(myValue);