-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathindex.js
132 lines (98 loc) · 1.51 KB
/
index.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
console.log(k)
function x ()
{
var a = 20;
if (true)
{
let b = 15;
console.log(a,b)
}
}
var k=20;
x()
//callback
function y (a, x)
{
console.log(a, x)
return x
}
y(5, x)
//Data types
//operator ?:,++,--
//loops,control statements
arr=[2,3,5,8,7,9]
for (let i = 0; i < arr.length; i++)
{
console.log(arr[i])
}
for (let i of arr)
{
console.log(i)
}
for (let i in arr)
{
console.log(arr[i])
}
arr.forEach((i) => console.log(i))
const p = arr.map((i) =>
{
console.log(i)
return i%2==0
})
const q = arr.filter((i) => {
console.log(i)
return i%2==0
})
console.log(p, q)
//lexical scoping
let obj = {
name: "raj",
age: 20,
}
function print (a,b)
{
console.log(this.name,this.age,a,b)
}
print.call(obj,5,6)
print.apply(obj,[5,6])
let r = print.bind(obj)
console.log(r)
r()
//events
//xmlHttpRequest
//fetch
//https://dummyjson.com/products
fetch("https://dummyjson.com/recipes")
.then((res) => res.json())
.then((data) => console.log(data))
async function fetchData ()
{
const res = await fetch("https://dummyjson.com/recipes")
const data = await res.json()
console.log(data)
}
fetchData()
//promises,await-async
//classes
class Iphone
{
name;
constructor(name)
{
this.name = name;
}
print ()
{
console.log(this.name)
}
}
class Iphone2 extends Iphone
{
constructor(name)
{
super(name)
}
}
export default Iphone
export {Iphone2}
//modules