Beginner Article: Writing Your First "Hello World" Program In Typescript
Photo Credits: GeeksforGeeks 2023

Beginner Article: Writing Your First "Hello World" Program In Typescript

If you're just starting out in coding, it can be overwhelming trying to figure out where to begin. One language that is worth taking a closer look at is TypeScript. Developed and maintained by Microsoft, TypeScript is open-source and free to use.


TypeScript is a superset of JavaScript that adds static types and other features to the language. It is designed to make large-scale JavaScript applications easier to develop and maintain. Some of the benefits of TypeScript include improved code quality, better collaboration between developers, and more efficient development.


Getting Started with TypeScript


To start using TypeScript, you'll need to have Node.js installed on your computer. You can download it from the official website and follow the instructions for your operating system.


Once Node.js is installed, you'll need to install TypeScript globally using the Node Package Manager (npm) by running the following command in your Terminal or Command Prompt:


npm install -g typescript


With TypeScript installed, you can now create your first TypeScript program. The best way to start is by writing a simple "Hello, World!" program. This will help you get familiar with the TypeScript syntax and how to use the language.


Writing the "Hello, World!" Program


Open up your code editor of choice (such as Visual Studio Code or Sublime Text) and create a new file called "hello.ts". This will be your TypeScript file.


In the file, type the following code:


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


This line of code simply prints "Hello, World!" to the console (which is a window in your browser that displays information to the user).


However, this code won't run yet because it's written in TypeScript. To compile the code into JavaScript (which is what the browser can understand), you'll need to run the TypeScript compiler.


Compiling the Code


In your Terminal or Command Prompt, navigate to the directory where your "hello.ts" file is located. Then, run the following command:


tsc hello.ts


This will compile the TypeScript code into JavaScript and create a new file called "hello.js". You can then run this file with the following command:


node hello.js


This will execute the JavaScript code and you should see "Hello, World!" printed to the console.


Congratulations! You've created your first TypeScript program.


Conclusion


Starting with TypeScript can be a great choice for beginners as it's easier to learn than some other languages, while still allowing for complex applications. Use "Hello, World!" as your starting point, and work on more challenging projects as you learn more about TypeScript. Good luck and happy coding!

* https://www.typescriptlang.org/docs/

* https://nodejs.org/en/docs

要查看或添加评论,请登录

Joseph DeMasse的更多文章

社区洞察

其他会员也浏览了