-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.js
53 lines (45 loc) · 1.05 KB
/
example.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
// This is a single-line comment
/**
* This is a multiline comment
* @param {number} a - The first number to add
* @param {number} b - The second number to add
* @returns {number} The sum of the two numbers
*/
function add(a, b) {
return a + b;
}
// Variable declarations
const message = 'Hello, World!';
let count = 10;
console.log(count)
// Arrow Function
const multiply = (x, y) => x * y;
// Promise Example
const fetchData = () => {
return new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Data fetched!');
}, 2000);
});
};
// Async/Await Example
async function fetchDataAsync() {
const data = await fetchData();
console.log(data);
}
// Class Example
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
console.log(`${this.name} says Hello!`);
}
}
// Creating an object and calling a method
const person = new Person('Alice', 30);
person.greet();
// Template Strings
const greeting = `My name is ${person.name} and I am ${person.age} years old.`;
console.log(greeting);