-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHeapandStack.js
More file actions
67 lines (40 loc) · 1.31 KB
/
HeapandStack.js
File metadata and controls
67 lines (40 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//Stack (all primitive datatypes) Heap(all non primitive data types)
let myyoutubename = "RKCreations"
let anothername = myyoutubename
anothername = "RutujaKolte"
console.log(myyoutubename);
console.log(anothername);
let Person = {
name: "John",
age: 25
};
let colours = ["red", "blue", "green"];
function sayHello() {
console.log("Hello!");
}
/*--------------------------------Stack-------------------------------*/
//Think of it like a stack of plates - items are added/removed from the top only
//Fixed amount of memory
//variables are automatically deleted when they are goes out of scoped
/*---------------------------------Heap------------------------------*/
//Think of it like a big storage room where you can put things anywhere
//Cleaned up by garbage collector when no longer referenced
// These are stored in Heap
let person = {
name: "John",
age: 25
};
let colors = ["red", "blue", "green"];
function sayHello() {
console.log("Hello!");
}
/*-------------Example------------------*/
/*
let age = 30; // Stored in Stack
let name = "John"; // Stored in Stack
let person = { // Reference stored in Stack, object stored in Heap
age: age,
name: name
};
let numbers = [1, 2, 3]; // Reference stored in Stack, array stored in Heap
*/