Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

typescript
hello world
beginner

How to write a "Hello World" program in TypeScript

Nouman Abbasi

TypeScript is an object-oriented language designed by Microsoft.

TypeScript is a superset of JavaScript that offers all of JavaScript’s features and TypeScript’s type system.

In this shot, we will see how to write a simple “Hello World” program in TypeScript.

svg viewer

Code

In this example, we declare a variable message of type string, and initialize it to ‘Hello World’. Unlike JavaScript, TypeScript is statically typedVariable types are explicitly declared and determined at compile time.; so, we explicitly mention the type string.


// Declare and initialize 'message' of type string
// to 'Hello World'.
let message: string = 'Hello World';

// Printing the message to console.
console.log(message);

TypeScript also supports type inference and will generate types in many cases.
In the example above, you can skip writing the type
(let message = 'Hello World';),
and TypeScript will correctly infer the type as string.

RELATED TAGS

typescript
hello world
beginner

CONTRIBUTOR

Nouman Abbasi
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses