-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlecture8.js
151 lines (110 loc) · 4.04 KB
/
lecture8.js
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//############### Question 1 ###################
// "==" operator example
/* "==" kewal values ko compare karta hai, agar values barabar hai too voo
retrun kardega "true" */
/* Example: 1 */
let a= 25;
let b= 25;
console.log(a==b); /* return "true" because both values are same */
/* Example: 2 */
let x= 25;
let y= 28;
console.log(x==y); /* return "false" because both values are not same */
/* "===" ye values ke saath saath variables ke type ko bhi check karega, Agar
"data type" and "values" dono same hai too hi ye (true) return karega. "values" + "datatype" = true
*/
// "===" operator example
/* Example: 1 */
let mango= 25;
let banana= 25;
console.log(typeof mango);
console.log(typeof banana);
console.log(mango === banana);
/* Example: 2 */
let shubh= "25";
let adarsh = 25;
console.log(shubh == adarsh); /* return "true" */
let akash = "25";
let nitesh = 25;
console.log(akash === nitesh); /* kyu ki "===" ye values ke saath saath data
type ko bhi check karta hai aur isme datatype dono ka alag alag hai,
akash = "25" //string
nitesh = 25; //number
isliye return "false" mila*/
//############### Question 3 ###################
/* Example 1 */
let ram = 29;
let shyam = 29;
console.log(ram==shyam); /* return "true" */
/* Example 2 */
let mohit = [25];
let shalini = [25];
console.log(mohit==shalini); /* return "false" */
/* here, array is the reference type data type which will get heap memory location.
so array will comparison both variable as the different address of the allocated memory address.
Here both address are not same, so the output will return "false".
Here, in heap memory, object will be created and the value will be stored in this object and this object
have a particular address and this address will decaled in both variables.
*/
/* Example 3 */
//object reference data type
let s1 = {
//Object
name: "Hanuman Ji jai ho"
}
let s2 = {
name: "Hanuman ji"
}
console.log(s1.name); //return "Hanuman ji"
console.log(s1==s2); //return false
/* yaha 2 object create hua hoga, then pehle object me name ki value aagyi "Hanuman ji" and iss object ka
jo reference hoga (matlab ki memory address) usko maine s1 me daal dia too mai assume karta hu ki
s1=10000ux and s1 fhir object ko point out karne laga.
*/
/*
yaha hum s1 ke help se name ko use kar sakte hai and print kar sakte hai, like
s1.name, console.log(s1.name);
yaha (.) jo hai voo reference operator hai
*/
/* Example 4 */
let s3 = s1;
console.log(s1==s3);
let s4 = s2;
console.log(s2==s4);
//example of global scope
var globalVar = "Hello World!";
console.log(globalVar);
// call this global scope variable in under the function
function myfun() {
//global variable use
console.log(globalVar);
}
/* function call here,return call
yaha pe maine function ko call kar lia
*/
myfun();
//function scope example
function myfun1(){
var javascript = "Awesome";
console.log(javascript);
}
console.log(javascript); //reference error come variable not defined
myfun1(); //return variable value
// Example 1: block scope example with help of "let" variable
var akshat = 25;
var govind = 25;
if (akshat == govind) {
console.log("This two boy are equal in brain teasure!");
let boys = "Awesome";
console.log(boys);
}
// console.log(boys);
// Example 2: block scope example with help of "const" variable
var anirudh = 25;
var seekha = 25;
if (anirudh == seekha) {
console.log("This two boy are equal in activity game!");
const hema = "Awesome Hema";
console.log(hema);
}
console.log(hema);