Skip to content

Commit 5b92e37

Browse files
first commit
0 parents  commit 5b92e37

20 files changed

+854
-0
lines changed

ArrowFunction.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const marks=[23,34,56,67,78,89]
2+
3+
const result=marks.map((num)=>{
4+
console.log(num*num)
5+
})

FetchAPI.js

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
try {
2+
const data = fetch('https://jsonplaceholder.typicode.com/todos/1')
3+
console.log(data)
4+
5+
data.then((data) => {
6+
console.log("Data: ",data)
7+
return data.json()
8+
})
9+
.then((res) => {
10+
console.log(res)
11+
})
12+
.catch((err) => {
13+
console.log(err)
14+
throw err
15+
})
16+
}
17+
catch(err){
18+
console.log("Error: ",err);
19+
}
20+
// async function FetchApi(){
21+
// try {
22+
// const data = await fetch("https://jsonplaceholder.typicode.com/todos/4")
23+
// console.log(await data.json())
24+
// }
25+
// catch (err){
26+
// console.log(err)
27+
// }
28+
// }
29+
//
30+
// FetchApi()
31+
32+
// const newuser={
33+
// name:"Sarthik",
34+
// job:"Intership"
35+
// }
36+
37+
// async function FetchApi(){
38+
// try {
39+
// const res = await fetch("https://reqres.in/api/users",{
40+
// method:"POST",
41+
// headers:{
42+
// 'Content-Type':'application/json'
43+
// },
44+
// body:JSON.stringify(newuser)
45+
// })
46+
// const data = await res.json();
47+
// if(!res.ok){
48+
// console.log(data.description)
49+
// return;
50+
// }
51+
// console.log("Add Data: ",data)
52+
// }
53+
// catch (err){
54+
// console.log(err)
55+
// }
56+
// }
57+
// FetchApi();
58+
59+
// async function FetchApi1(){
60+
// try {
61+
// const res = await fetch("https://reqres.in/api/users/39",{
62+
// method:"PUT",
63+
// headers:{
64+
// 'Content-Type':'application/json'
65+
// },
66+
// body:JSON.stringify({
67+
// name:"xyz"
68+
// })
69+
// })
70+
// const data = await res.json();
71+
72+
// if(!res.ok){
73+
// console.log(data.description)
74+
// return;
75+
// }
76+
// console.log("Update Data",data)
77+
// }
78+
// catch (err){
79+
// console.log(err)
80+
// }
81+
// }
82+
// FetchApi1();
83+
84+
// async function FetchApi2(){
85+
// try {
86+
// const res = await fetch("https://reqres.in/api/users/3", {method:"DELETE"})
87+
// const data = await res.json();
88+
// if(!res.ok){
89+
// console.log(data.description)
90+
// return;
91+
// }
92+
// console.log("delete data",data)
93+
// }
94+
// catch (err){
95+
// console.log(err)
96+
// }
97+
// }
98+
99+
// FetchApi2();
100+
101+
102+
const newuser = {
103+
name: "Sarthik",
104+
email: "Fack@gmail.com"
105+
}
106+
107+
url = 'https://jsonplaceholder.typicode.com/users'
108+
109+
110+
// const data = fetch(url, {
111+
// method: 'POST',
112+
// headers: {
113+
// 'Content-Type': 'application/json'
114+
// },
115+
// body: JSON.stringify(newuser)
116+
// })
117+
// data.then((response)=>{
118+
// if(!response.ok){
119+
// throw new Error('POST is not working')
120+
// }
121+
// return response.json()
122+
// })
123+
// .then((data)=>{
124+
// console.log("============",data);
125+
// })
126+
// .catch((err)=>{
127+
// console.log(err);
128+
// })
129+
130+
131+
const data=fetch(url,{
132+
method:'DELETE',
133+
})
134+
data.then((response)=>{
135+
if(!response.ok){
136+
throw new Error('Delete not working')
137+
}
138+
return response.json()
139+
})
140+
.then((data)=>{
141+
console.log("===========",data);
142+
})
143+
.catch((err)=>{
144+
console.log("========",err);
145+
})

Function.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
function func1(num1,num2,call){
2+
console.log("This is a Func1")
3+
// return num1+num2
4+
call();
5+
}
6+
7+
function func2(name){
8+
console.log("This is a func2")
9+
// console.log(`${name}`)
10+
}
11+
12+
13+
function User(username,loginCount,isLoggedIn){
14+
this.username=username //variable = this value is you passed
15+
}
16+
17+
18+
// HighOrder Function
19+
function func(){
20+
return function func3(){
21+
22+
}
23+
}
24+
25+
func()()
26+
// or
27+
28+
const f=func("hi")
29+
f("hii")

Hoisting.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//function Hoisting
2+
3+
sum(5,5)
4+
5+
function sum(a,b){
6+
console.log(a+b);
7+
}
8+
9+
10+
// Hoisting is not working because function hoisting is work only function function_name(){}
11+
12+
// method1: // it is working but it is not call Hoisting
13+
sum1(5,6) // (function sum1(a,b){
14+
// console.log(a+b);
15+
(function sum1(a,b){ // })
16+
console.log(a+b);
17+
}) // sum1(5,6)
18+
19+
20+
//method 2:
21+
22+
sum2(5,6) // const sum=(a,b)=>{
23+
// console.log(a+b);
24+
const sum=(a,b)=>{ // }
25+
console.log(a+b); //sum(7,8)
26+
}
27+
28+

JSON.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// const json = '{"result":true, "count":10}';
2+
// const obj = JSON.parse(json);
3+
//
4+
// console.log(obj.result);
5+
// console.log(obj.count);
6+
7+
// JSON.stringify
8+
console.log(JSON.stringify({ x: 5, y: 6 }));
9+
10+
console.log(JSON.stringify(new Date(2004, 5, 12, 15, 4, 5)));

Object.js

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
let person = {
2+
name: "Sarthik",
3+
"address one": {
4+
state: "Gujarat",
5+
country: "India"
6+
},
7+
fn: function () {
8+
console.log(`my name is ${this.name} and live in ${this.address}`);
9+
}
10+
};
11+
12+
let key1='address one'
13+
console.log(person[key1]);
14+
15+
let person2 = {
16+
name: "xyz",
17+
age: 25,
18+
qualification: "B.tech"
19+
};
20+
// console.log(Object.assign(person,person2))
21+
22+
23+
let person3 = Object.create(person);
24+
person3.name = "ABC";
25+
person3.age = 23;
26+
console.log(Object.assign(person, person3));
27+
28+
// console.log(person.name);
29+
// console.log(person.address);
30+
// console.log(person.fn);
31+
32+
// Access method
33+
34+
// 1.Dot notation
35+
console.log("Dot notation: ", person2.name);
36+
37+
//2. Bracket Notation
38+
console.log("Bracket: ", person2["name"]);
39+
console.log("Bracket: ", person2["qualification"]);
40+
41+
//3.Accessing keys
42+
console.log("Access key: ", Object.keys(person3));
43+
44+
//4.using value
45+
const key = "age";
46+
console.log("Value: ", person2[key]);
47+
48+
//5.object Destructuring
49+
const { name, age } = person;
50+
console.log("Object: ", name);
51+
console.log("object: ", age);
52+
53+
//6.object entries
54+
console.log("Entries: ", Object.entries(person));
55+
56+
//7.object value
57+
console.log("object value: ", Object.values(person));
58+
59+
//8.for in loop
60+
for (let key in person) {
61+
console.log(key, person[key]);
62+
}
63+
64+
//9.Using Map object
65+
66+
const personMap = new Map([["name", "Sarthik"], ["age", 20]]);
67+
68+
console.log("Map name: ", personMap.get("name"));
69+
console.log("Map age: ", personMap.get("age"));

Promise.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
const promise1=new Promise((resolve,reject)=>{
2+
setTimeout(() => {
3+
resolve(1)
4+
},2001);
5+
})
6+
7+
const promise2=new Promise((resolve,reject)=>{
8+
setTimeout(() => {
9+
resolve(2)
10+
},3000);
11+
})
12+
13+
const promise3=new Promise((resolve,reject)=>{
14+
setTimeout(() => {
15+
reject(3)
16+
},500);
17+
})
18+
19+
20+
// console.time("start: ");
21+
// promise1.then((a)=>{
22+
// console.log(a);
23+
// })
24+
// .catch((e)=>{
25+
// console.log(e);
26+
// })
27+
28+
// promise2.then((a)=>{
29+
// console.log(a);
30+
// })
31+
// .catch((e)=>{
32+
// console.log(e);
33+
// })
34+
35+
// promise3.then((a)=>{
36+
// console.log(a);
37+
// })
38+
// .catch((e)=>{
39+
// console.log(e);
40+
// })
41+
42+
// console.timeEnd("start: ");
43+
44+
const fun=async function p1(){
45+
46+
try{
47+
// console.time("start: ")
48+
// const a=await promise1
49+
// console.log(a);
50+
51+
// const b=await promise2
52+
// console.log(b);
53+
54+
// const c=await promise3
55+
// console.log(c);
56+
// console.timeEnd("start: ")
57+
58+
const l=await Promise.allSettled([promise1,promise2,promise3])
59+
console.log('++++++++++',l);
60+
61+
}
62+
63+
catch(e){
64+
console.log(e);
65+
}
66+
67+
finally{
68+
console.log("running");
69+
}
70+
}
71+
fun()
72+
73+
74+
// Promise chaining
75+
76+
// console.time("start: ");
77+
// promise1.then((a)=>{
78+
// console.log(a);
79+
// return promise2
80+
// })
81+
// .then((b)=>{
82+
// console.log(b);
83+
// return promise3
84+
// })
85+
// .then((c)=>{
86+
// console.log(c);
87+
// console.timeEnd("start: ")
88+
// })
89+
// .catch((e)=>{
90+
// console.log(e);
91+
// })
92+
93+
Promise.allSettled([promise1,promise2,promise3]).then((a)=>{
94+
console.log("running a:",a);
95+
console.log("running b:",b);
96+
console.log("running c:",c);
97+
98+
})
99+
.catch((e)=>{
100+
console.log(e);
101+
})
102+
103+
104+
//allsettled,all
105+

0 commit comments

Comments
 (0)