forked from panache-chinmay/javascriptDeccan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript8.js
More file actions
250 lines (171 loc) · 4.54 KB
/
Copy pathscript8.js
File metadata and controls
250 lines (171 loc) · 4.54 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/* Defining variables with let and constant
1) Till now we have only one way of declaring javascript i.e
using let and const keyword
*/
// var message = "Hello";
// const pi = 3.14159;
// let score = 0 ;
/*
creating unchanging variable with const keyword
1) const means the value the variable should not change
2) const pi = 3.14 ;
3) const should be the first chioce of programmer, when they want something
that should not be changed once the program runs
Examples :- Dimensions of user interface components , product prices
4) When you want to change the value of variable in program , const is bad choice
example :- playing any software updation game .
//common problem where you can use the javscript 'const' keyword.
5) You cannot change the value of const variable
6 ) Making the variable const inside the function , make it to the same scope and hence
the erroe is gone
*/
// var x = 200;
// function abc(){
// var x = 100 ;
// console.log(x);
// }
//
// console.log(abc());
// console.log(x
// const x = 200;
// function abc(){
// const x = 100 ;
// console.log(x);
// }
//
// console.log(abc());
// console.log(x)
//
// let x = 200;
// function abc(){
// let x = 100 ;
// console.log(x);
// }
//
// console.log(abc());
// console.log(x)
// Same output for all three cases
/*
using consts and Arrays with objects
*/
// Arrays and Objects with var keyword
/*
var x = 10 ;
x = "Ankita Gupta";
console.log(x);
var y = {
name:"Chinmaya",
rollNumber:89
};
y = [19,20,21]
console.log(y);
*/
// Arrays and Objects with const
// const abc = [2,4,5,6]
// abc.push(9);
// console.log(abc);
// We can modified Array with const keyword
// We cannot assign new data struture to same variable if we defined it with data type
// abc = {
// name:"ChinmayDespande",
// rollNumber:78
// }
// console.log(abc)
//----------------------------------------------------------------------------->
// We can modified object with const variable but cannot assigned new data struture to Same variable
// Not also of same type
//
// const dce = {
// name:"Ninad",
// rollNumber:78
// }
// dce.lastname = "Dani";
// dce = [8,9,999,98,99];
// console.log(dce);
// Not also of same type
//----------------------------------------------------------------------------->
// Defining varibale with let keyword ..
// Let just work like var
// you can re-assign values using let keyword
//------------------------------------------------------------------------------>
// Varibles are function scoped
// let and constant have blocked scope.
// with car
// const person = {
// first_name:"Andrew",
// role:"Teacher"
// }
//
// function personDescription(person){
//
// var description = person.first_name;
// if(person.role){
// description = description + "is a ";
// description = description + person.role;
// }
// console.log(description)
// }
//
// personDescription(person);
// With const
// Assignment to the const
// const person = {
// first_name:"Andrew",
// role:"Teacher"
// }
//
// function personDescription(person){
//
// const description = person.first_name;
// if(person.role){
// description = description + "is a ";
// description = description + person.role;
// }
// console.log(description)
// }
//
// personDescription(person);
// Using let keyword
// const person = {
// first_name:"Andrew",
// role:"Teacher"
// }
//
// function personDescription(person){
//
// let description = person.first_name;
// if(person.role){
// description = description + "is a ";
// description = description + person.role;
// }
// console.log(description)
// }
// personDescription(person);
// Use of let in for loop -
// const buttons = document.getElementsByTagName('button');
//
// for(var i = 0 ; i < buttons.length ; i++){
// const button = buttons[i];
// button.addEventListener("click",function(){
// alert("Button " +i+ " Pressed");
// });
// }
// const buttons = document.getElementsByTagName('button');
//
// for(let i = 0 ; i < buttons.length ; i++){
// const button = buttons[i];
// button.addEventListener("click",function(){
// alert("Button " +i+ " Pressed");
// });
// }
for(let j = 0 ; j < 10 ; j++){
console.log(j);
}
//console.log(j);
// More on let and constant keyword..
/*
constants are first option while declaring varaible
const is used for values you never want reassigning
let is used for the values you want to reassign (When used in block scope i.e in for loop)
var usage should be avoided when used in for loop
*/