-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex14.js
72 lines (57 loc) · 1.3 KB
/
index14.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
//encapsulation
class Alien{
constructor(){
let age,name;
}
setAge(age){
this.age=age;
}
setName(name){
this.name=name;
}
getAge(){
return this.age;
}
getName(){
return this.name;
}
}
let a=new Alien();
a.setAge(28);
a.setName("Maithaly");
console.log(a.getAge());
console.log(a.getName());
/* difference var,let,const */
var aa="Telusko";//declare
var aa = "Alien";//redeclare and reassign
console.log(aa);//ALien
let aaa="Maithaly";
//let aaa="iNeuron";//error redeclared
aaa="Ineuron"//reassign is allowed
console.log(aaa);//Ineuron
const aaaa="telusko";
//aaaa ="maithaly";//error reassign is not allowed
console.log(aaaa);
/* statically and dynamically
static type means you have to define its datatype
let int a= 29;
dynamic types means you dont have to declare its datatype
let a= 29;
*/
/* scope */
//global scope
if(true){
var a1="maith";
console.log(a1);//maith
}
console.log(`outside ${a1}`);//outside maith
if(true){
let a2="maith";
console.log(a2);//maith
}
//console.log(`outside ${a2}`);//error scope is till inside the method
if(true){
const a3="maith";
console.log(a3);//maith
}
//console.log(`outside ${a3}`);//error