Basic Syntax in TypeScript



In this tutorial, we will learn the basic syntax of TypeScript language. We will go through the key components of a simple TypeScript program.

TypeScript Program

console.log('Hello, World!');

Output

Hello, World!

Basic Syntax of a TypeScript Program

  1. console.log('Hello, World!');
    This line uses the console.log function to output the string "Hello, World!" to the console or standard output.

Key Points to Remember

  • All TypeScript statements must end with a semicolon (;).
  • TypeScript is a superset of JavaScript and shares most of its syntax, but it adds static typing and other features for large-scale applications.
  • Comments can be added using // for single-line comments or /* ... */ for multi-line comments, similar to JavaScript.
  • TypeScript is transpiled to JavaScript during compilation, making it compatible with all JavaScript environments.