Skip to content

Commit 6384080

Browse files
twelth commit
1 parent 70950e4 commit 6384080

File tree

5 files changed

+135
-0
lines changed

5 files changed

+135
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Primitive Data Type vs c
2+
3+
// Primitive Data Type
4+
// there are 7 primitive data type
5+
// 1. string
6+
// 2. number
7+
// 3. boolean
8+
// 4. bigint
9+
// 5. undefined
10+
// 6. symbol
11+
// 7. null
12+
// Primitive -------> value are stores in Stack Memory
13+
// for primitive type variables diffrent memory block created for each variable.
14+
let num1 = 6;
15+
let num2 = num1;
16+
console.log("value is num1 is", num1);
17+
console.log("value is num2 is", num2);
18+
num1++;
19+
console.log("After Incrementing num1");
20+
console.log("value is num1 is", num1);
21+
console.log("value is num2 is", num2);
22+
23+
24+
// References Data Type
25+
// 1. Objects
26+
// 2. Functions
27+
// 3. Collections
28+
// 4. Arrays
29+
// 5. Dates
30+
// 6. other types of objects
31+
32+
// Reference Types -----> values are stores in Heap Memory
33+
// The object itself is stored on a heap, and its pointer is stored on a stack.
34+
// The pointer is identified by the object's variable name, and points to that object.
35+
// array --> stores in Heap
36+
// array1 & array2 are store in stack(contains address of Heap memory)
37+
// and address point to the Heap memory where data are store.
38+
let array1 = ["item1", "item2"];
39+
let array2 = array1;
40+
console.log("array1", array1);
41+
console.log("array2", array2);
42+
array1.push("item3"); // item3 is store in Heap
43+
console.log("After pushing element to Array1")
44+
console.log("array1", array1);
45+
console.log("array2", array2);

JavaScript Part-01/27ArrayClone.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// How to Clone Arrray
2+
3+
let array1 = ["item1", "item2"];
4+
5+
// let array2 = ["item1", "item2"]; // not effective
6+
7+
8+
// clonning using slice method ---> fast method
9+
10+
// let array2 = array1.slice(0); // 0(st idx) --> n(last idx)
11+
// let array2 = array1.slice(0).concat(["item3", "item4"]); // adding new elements
12+
13+
14+
// clonning using Concatination
15+
16+
// let array2 = [].concat(array1);
17+
// let array2 = [].concat(array1, ["item3", "item4"]); // clonning and adding new elements
18+
19+
let oneMoreArray = ["item3", "item4"];
20+
// New Way
21+
// spread operator
22+
// let array2 = [...array1];
23+
// let array2 = [...array1, "item3", "item4"]; // adding new elements
24+
let array2 = [...array1, ...oneMoreArray];
25+
26+
array1.push("item3");
27+
console.log(array1===array2);
28+
console.log(array1);
29+
console.log(array2);

JavaScript Part-01/28ArrayForLoop.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// for Loop In Array
2+
3+
let fruits = ["apple", "mango", "grapes", "banana"];
4+
// for(let i=0; i<=9; i++){
5+
// console.log(i);
6+
// }
7+
8+
// console.log(fruits.lenght); // size of array
9+
// console.log(fruits[fruits.length-1]); // last index
10+
11+
for(let i=0; i<fruits.length; i++){
12+
console.log(fruits[i]);
13+
// console.log(fruits[i].toUpperCase()); // printing in upper case
14+
}
15+
16+
17+
// creating new array
18+
let fruits2 = [];
19+
for(let i=0; i<fruits.length; i++){
20+
fruits2.push(fruits[i].toUpperCase());
21+
}
22+
console.log(fruits2);

JavaScript Part-01/29ConstArray.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Use Const For Creating Array
2+
3+
// jab bhi koi reference data type use karenge tab "const" use karenge
4+
// heap memory ["apple", "mango"] 0x11(address)
5+
6+
const fruits = ["apples", "mango"]; // 0x11
7+
// fruits = ["banana", "waterlaemon"];
8+
// we can't assign 'fruits' with new array in const this is not allowed
9+
fruits.push("banana"); // we can arrays method
10+
console.log(fruits);
11+
12+
// use of "const" are safe and preffred
13+
14+
// this is the diffrences in const & let
15+
let fruits2 = ["apples", "mango", "kiwi"]; // 0x11
16+
fruits2 = ["grapes", "pineapple"];
17+
// when we use let the assing new value in fruit are allowed
18+
fruits2.push("banana");
19+
console.log(fruits2);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// While loop in Arrray
2+
3+
const fruits = ["apple", "mango", "grapes", "banana"];
4+
5+
// let i = 0;
6+
// while(i<fruits.length){
7+
// console.log(fruits[i].toUpperCase());
8+
// i++;
9+
// }
10+
11+
12+
// creatin new array in upper case
13+
const fruits2 = [];
14+
15+
let k = 0;
16+
while(k<fruits.length){
17+
fruits2.push(fruits[k].toUpperCase());
18+
k++;
19+
}
20+
console.log(fruits2);

0 commit comments

Comments
 (0)