-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrev2.js
More file actions
129 lines (98 loc) · 1.9 KB
/
rev2.js
File metadata and controls
129 lines (98 loc) · 1.9 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
//var const let
let a=5
var b=1
const c=3
console.log("original values",a,b,c)
a=6
b=2
// c=4
console.log("updated values",a,b,c)//giving error bc of c
function abcd(){
var d=3 //function scoped
if(1){
const e=4
let f=5 // braces scoped
console.log(e,f,d)
}
}
abcd()
// var add itself in window obj which is highly insecure for data privacy thats why let and const
//were introduced which if defined in script.js will not add themself in window obj
//simple function
let fun=function(){
console.log("one way of defining function")
}
fun()
function xyz(){
console.log("second way of defining function")
}
xyz()
//arrow function
let erg=()=>{
console.log("this is arrow function")
}
erg()
//object
var obj={}//blank obj
console.log(obj)
var obj1={
name:"mak",
class:2,
work:function(){
console.log("study")
}//method
}
console.log(obj1)
console.log(obj1.work)
obj1.name="kam"
console.log(obj1.name)
//obj destructuring
const {name}=obj1
console.log(name)
//arrays
//foreach
var arr=["mak","pet",2,{model:10,color:"white"},[a,b,c]]
arr.forEach((item)=>{
console.log(item)
})
//map
var arr=[1,"hash"]
const newarr=arr.map((item)=>{
return item
})
console.log(newarr)
//filter
var arr1=[1,2,3,4,5,6,7,8,9,10]
const newarr1=arr1.filter((item)=>{
if(item<=5)
return item
})
console.log(newarr1)
//find
var arr2=[3,2,4,5,2]
var newarr2=arr2.find((item)=>{
if(item==2){
return item
}
})
console.log(newarr2)
//class
//template
class person{
constructor(name,age){
this.name=name;
this.age=age;
}
details(){
console.log(this.name,"is",this.age,"years old");
}
}
let p1=new person("Jane",12)
p1.details();
//async await
async function api(){
let data= await fetch("https://dummyjson.com/test")
let output=data.json()
console.log(output)
}
api();