57 lines
1.2 KiB
JavaScript
57 lines
1.2 KiB
JavaScript
/**
|
|
* A simple function to calculate the sum of two numbers.
|
|
*
|
|
* @param {number} a - The first number.
|
|
* @param {number} b - The second number.
|
|
* @returns {number} The sum of the two numbers.
|
|
*/
|
|
|
|
function add(a, b) {
|
|
return a + b;
|
|
}
|
|
|
|
/**
|
|
* Logs a greeting message to the console.
|
|
*
|
|
* @param {string} name - The name to greet.
|
|
*/
|
|
function greet(name) {
|
|
console.log(`Hello, ${name}!`);
|
|
}
|
|
|
|
// Example usage
|
|
const result = add(5, 10);
|
|
|
|
console.log(`The result is: ${result}`);
|
|
|
|
greet("Alice"); // Replaced 'Alice' with "Alice"
|
|
|
|
/**
|
|
* An example class demonstrating basic TypeScript features in JavaScript.
|
|
*/
|
|
class Person {
|
|
/**
|
|
* Creates an instance of Person.
|
|
*
|
|
* @param {string} name - The name of the person.
|
|
* @param {number} age - The age of the person.
|
|
*/
|
|
constructor(name, age) {
|
|
this.name = name;
|
|
this.age = age;
|
|
}
|
|
|
|
/**
|
|
* Introduces the person.
|
|
*
|
|
* @returns {string} A greeting message.
|
|
*/
|
|
introduce() {
|
|
return `Hi, I'm ${this.name} and I'm ${this.age} years old.`;
|
|
}
|
|
}
|
|
|
|
// Example usage of the Person class
|
|
const person = new Person("Bob", 25); // Replaced 'Bob' with "Bob"
|
|
console.log(person.introduce());
|