Skip to content

Commit 5e9ede9

Browse files
author
Nasser X
committed
JS/ES6
1 parent b7fceb4 commit 5e9ede9

File tree

5 files changed

+540
-0
lines changed

5 files changed

+540
-0
lines changed

JavaScript/index.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<!DOCTYPE html>
2+
<html>
3+
4+
<head>
5+
<meta charset="utf-8">
6+
<title>JavaScript Tutorial</title>
7+
</head>
8+
9+
<body>
10+
<p id="example"></p>
11+
</body>
12+
13+
<!-- <script src="../JavaScript /scripts/js.js"></script> -->
14+
<script src="../JavaScript/scripts/es6.js" type="module"></script>
15+
</html>

JavaScript/scripts/animal.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
export class Animal {
2+
constructor(type, legs) {
3+
this.type = type;
4+
this.legs = legs;
5+
}
6+
7+
MakeNoise(sound = "Loud Noise") {
8+
console.log(sound);
9+
}
10+
11+
get MetaData() {
12+
return `Type: ${this.type}, Legs: ${this.legs}`;
13+
}
14+
15+
static return10() {
16+
return 10;
17+
}
18+
}
19+
20+
export class Cat extends Animal {
21+
constructor(type, legs, tail) {
22+
super(type, legs);
23+
this.tail = tail;
24+
}
25+
MakeNoise(sound = "Meow") {
26+
console.log(sound);
27+
}
28+
29+
30+
}

JavaScript/scripts/es6.js

+248
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,248 @@
1+
//Start
2+
console.log("--Start--");
3+
4+
let word1 = "Nasser";
5+
let word2 = "BinObied";
6+
let num1 = 2;
7+
let num2 = 3;
8+
9+
const FullName = word1 +" " + word2;
10+
const FullName1 = `${word1} ${word2}`;
11+
const sum = `${num1 + num2} ${word2}`;
12+
13+
console.log(FullName);
14+
console.log(FullName1);
15+
console.log(sum);
16+
17+
let example = "Hello \n" + "World";
18+
let example2 = `${word1}
19+
${word2}
20+
`;
21+
console.log(example);
22+
document.getElementById("example").innerText = example2;
23+
24+
//Destructuring
25+
console.log("--Destructuring--");
26+
27+
// const PersonalInformation = {
28+
// FirstName: "Nasser",
29+
// LastName: "BinObied",
30+
// City: "Riyadh",
31+
// State: "Riyadh",
32+
// ZipCode: 12477
33+
// };
34+
35+
// const {FirstName: fn, LastName: ln} = PersonalInformation;
36+
37+
// console.log(`${FirstName} ${LastName}`);
38+
// console.log(`${fn} ${ln}`);
39+
40+
//Destructuring Arrays
41+
console.log("--Destructuring Arrays--");
42+
43+
let [FirstName, MiddleName, LastName] = ["Nasser", "Sad Engineer", "BinObied"];
44+
LastName = "AlRammal";
45+
46+
console.log(LastName);
47+
48+
//Object Literal
49+
console.log("--Object Literal--");
50+
51+
function AddressMaker(city, state) {
52+
const NewAddress = {city, state}
53+
console.log(NewAddress);
54+
55+
}
56+
57+
AddressMaker("Riyadh", "Riyadh");
58+
59+
function AddressMaker2(address) {
60+
const {city, state} = address;
61+
const NewAddress = {
62+
city,
63+
state,
64+
country: "KSA"
65+
}
66+
console.log(`${NewAddress.city}, ${NewAddress.state}, ${NewAddress.country}`);
67+
}
68+
AddressMaker2({city: "Riyadh", state: "ArrRiyadh"});
69+
70+
//For Loop
71+
console.log("--For Loop--");
72+
73+
let Incomes = [6200, 67000, 75000];
74+
let Total = 0;
75+
76+
// for (const income of Incomes) {
77+
// console.log(income);
78+
// Total += income;
79+
// }
80+
81+
console.log(Total);
82+
83+
let fullName = "Nasser BinObied";
84+
85+
for (let char of fullName) {
86+
console.log(char);
87+
}
88+
89+
for (let income of Incomes) {
90+
income += 5000;
91+
console.log(income);
92+
}
93+
94+
//Spread Operation
95+
console.log("--Spread Operation--");
96+
97+
let SpreadExample = [1,2,3,4,5,6];
98+
99+
let SpreadExample2 = {
100+
firstName: "Nasser"
101+
}
102+
103+
let SpreadExample3 = {
104+
...SpreadExample2
105+
}
106+
console.log(SpreadExample3);
107+
108+
//Rest Operation
109+
console.log("--Rest--");
110+
111+
// function Add(...numbers){
112+
// console.log(numbers);
113+
114+
// };
115+
116+
// Add(2,3,4,5,6)
117+
118+
//Arrow Function
119+
console.log("--Arrow Function--");
120+
121+
function Add(...numbers){
122+
// let Total = numbers.reduce(function (x,y){
123+
// return x+y;
124+
// });
125+
let Total = numbers.reduce((x,y) => x + y);
126+
console.log(Total);
127+
};
128+
129+
Add(2,3,4,5,6);
130+
131+
//Default Params
132+
console.log("--Default Params--");
133+
134+
function AddArray(NumberArray = []) {
135+
let total = 0;
136+
NumberArray.forEach(element => {
137+
total += element;
138+
});
139+
console.log(total);
140+
};
141+
AddArray();
142+
143+
//includes()
144+
console.log("--includes()--");
145+
146+
let NumberArray = [1,2,3,4,5,6];
147+
console.log(NumberArray.includes(0));
148+
149+
//Let/Const
150+
console.log("--Let/Const--");
151+
152+
if(false){
153+
var example1 = 5;
154+
};
155+
console.log(example1);
156+
157+
//Import/Export
158+
console.log("--Import/Export--");
159+
160+
// import { data } from './export.js';
161+
// let UpdateData = data;
162+
163+
// UpdateData.push(5);
164+
165+
// console.log(UpdateData);
166+
167+
//padStart/padEnd
168+
console.log("--padStart/padEnd--");
169+
let PadExample = "Nasser";
170+
171+
console.log(PadExample.padEnd(10, "x"));
172+
173+
//Classes
174+
console.log("--Classes--");
175+
176+
import { Animal, Cat } from "./animal.js";
177+
let cat = new Cat("Cat", 4);
178+
179+
cat.legs = 3;
180+
cat.MakeNoise();
181+
console.log(cat);
182+
183+
console.log(Animal.return10());
184+
185+
console.log(cat.MetaData);
186+
187+
//Trailing Commas
188+
console.log("--Trailing Commas--");
189+
function AddCommas(param1,) {
190+
const example = {
191+
name: "Dylan",
192+
};
193+
console.log(example);
194+
};
195+
AddCommas(2);
196+
197+
//Async/Await
198+
console.log("--Async/Await--");
199+
200+
const apiUrl = 'https://fcctop100.herokuapp.com/api/fccusers/top/alltime';
201+
202+
// async function getTop100Campers() {
203+
// const respone = await fetch(apiUrl);
204+
// const json = await respone.json();
205+
// console.log(json[0]);
206+
// }
207+
208+
// function getTop100Campers() {
209+
// fetch(apiUrl)
210+
// .then((r) => r.json())
211+
// .then((json) => {
212+
// console.log(json[0]);
213+
// }).catch((error) => {
214+
// console.log("failed");
215+
// });
216+
// }
217+
218+
// getTop100Campers();
219+
220+
// function resolveAfter3Seconds() {
221+
// return new Promise(resolve => {
222+
// setTimeout(() => {
223+
// resolve("resolved")
224+
// }, 3000);
225+
// });
226+
// };
227+
228+
// resolveAfter3Seconds().then((data) => {
229+
// console.log(data);
230+
// });
231+
232+
// async function getAsyncData() {
233+
// const result = await resolveAfter3Seconds();
234+
// console.log(result);
235+
// };
236+
237+
// getAsyncData();
238+
239+
//Sets
240+
console.log("--Sets--");
241+
242+
const SetExample = new Set([1,1,1,1,2,2,2,2]);
243+
SetExample.add(5);
244+
245+
console.log(SetExample.delete(5));
246+
247+
248+
console.log(SetExample.size);

JavaScript/scripts/export.js

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
const data = [1,2,3];
3+
export {data};

0 commit comments

Comments
 (0)