-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathES8.js
More file actions
43 lines (35 loc) · 974 Bytes
/
ES8.js
File metadata and controls
43 lines (35 loc) · 974 Bytes
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
// 1. Async/Await
const fetchData = async () => {
return "Data fetched!";
};
// Example usage
const getData = async () => {
const data = await fetchData();
console.log(data); // Data fetched!
};
getData();
// Another example with error handling
const fetchWithError = async () => {
throw new Error("Fetch error!");
};
const getDataWithErrorHandling = async () => {
try {
const data = await fetchWithError();
console.log(data);
} catch (error) {
console.error(error.message); // Fetch error!
}
};
getDataWithErrorHandling();
// 2. Object.values() and Object.entries()
const user = {
name: "Alice",
age: 30,
city: "New York"
};
// Example usage of Object.values()
const values = Object.values(user);
console.log(values); // ['Alice', 30, 'New York']
// Example usage of Object.entries()
const entries = Object.entries(user);
console.log(entries); // [['name', 'Alice'], ['age', 30], ['city', 'New York']]