How to Use the Typescript
// hello-world.ts
// Define a variable with a string type
let greeting: string = "GFG";
// Output the greeting to the console
console.log(greeting);
Explanation of the code:
- Variable Declaration: In TypeScript, variables can be declared using the let keyword, similar to JavaScript. Here, let greeting declares a variable named greeting.
- Type Annotation: TypeScript allows you to specify the data type of a variable using type annotations. In this case, : string indicates that the variable greeting should hold a string value.
- Initialisation: The variable greeting is initialised with the string value “GFG”.
- Console Output: The console.log statement is used to output the value of greeting to the console. This is a common way to display messages or data during program execution.
Output:
GFG
Contact Us