-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.js
More file actions
94 lines (71 loc) · 1.85 KB
/
variable.js
File metadata and controls
94 lines (71 loc) · 1.85 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
//Ways to declare a variable
//var, let ,const
// let firstName='Shalini';
// let lastName='C';
// console.log(firstName,lastName,age);//can't access age before initialization.
// //you get error
// let age=30;//Initialization of varibale
// console.log(age);
// let firstName='Shalini';
// let lastName='C';
// console.log(firstName,lastName,age);//can be accessed.
// //you get undefined
// let age=30;//Initialization of varibale
// console.log(age);
//Naming Conventions
//-Only letters,numbers,underscores and dollar signs
//-Can't start with a number
//Multi-Word Formatting
//firstName=camelCase
//first_Name=underscore
//FirstName=PascalCase
//firstname=lowerCase
//Re-assigning Variables
// age=31;
// console.log(age);
// let score;
// score=1;
// console.log(score);
// if(true){
// score+=1;
// }
// console.log(score);
//const can't be directly re-assigned
// const x=100;
// x=200;
// console.log(x);
//declare it but not intialized then it is error
// const score1;
//can i have array with const? Yes
// const arr=[1,2,3,4,5];
// arr.push(6);
// console.log(arr);
// const person ={
// name:'Shalu',
// };
// person.name='john';
// person.email='shalu@gmail.com';
// console.log(person);
//we can declare multiple values at once.
// let a,b,c;
// const d=10,e=20,f=30;
// console.log(d);
// console.log(a);
// var - Variable can be re-declared and Updated. A gobal scope variable.
// let - Variable cannot be re-declared but can be updated.A blcok scope variable.
// const - Variable cannot be re-declared or updated.A blcok scope variable.
// var age=24;
// var age=59;
// var age=84;
// console.log(age); //correct but not used nowadays
// let age=24;
// let age=59;
// let age=84;
// console.log(age);//incorrect
const age=24;
age=98;
console.log(age);//incorrect
let a1;
console.log(a);//undefined
// const a;
// console.log(a);//incorrect