Functions in TypeScript are similar to functions in JavaScript, but TypeScript allows you to define the types of the parameters and the return type of the function, adding type safety and improving the development experience.
Basic Function
function greet(name: string): string {
return `Hello, ${name}!`;
}
console.log(greet("John")); // Output: Hello, John!
name: string specifies that the name parameter must be a string.
: string after the parentheses specifies that the function returns a string.
Негізгі бет What is Typescript Function in Hindi | Example of Function in Typescript | Typescript tutorial-12
Пікірлер