Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Syntax | TypeScript Fundamentals
Introduction to TypeScript

SyntaxSyntax

TypeScript is an extension for JavaScript, and it is applied on top of this code. The basic syntax of JavaScript and TypeScript is identical, so if you already know the basics of JavaScript, you will find it much easier to understand this course. However, even in that case, I recommend you complete the tasks to review the fundamentals.

If you have never worked with JavaScript before - no problem. In this course, we will cover the basic syntax, which is the same for both TypeScript and JavaScript.

Let's start with printing text to the console:

To display information in the console, we use the following syntax:

Please note that the text we want to output to the console is enclosed in double-quotes (""). You can change the text in the code window above to experiment!

Note

Using a semicolon (;) at the end of a line in the code is optional.

With this command, you can also log anything on the console. Let's look at an example:

Note

We don't use double quotes ("") when printing numbers; double quotes are only used for text!

You can also combine numbers and text using template literals. This syntax is available in both TypeScript and JavaScript.

You should use backticks instead of double quotes. Also, you need to enclose values (numbers or variable names) in this syntax: ${variable/number}. Let's look at an example:

Note

var is a somewhat outdated way of declaring a variable. Nowadays, let is more commonly used for variable declaration, and const is used for declaring constants (variables that cannot be changed after initialization).

In the code example above, you can see how we created and used a variable. In the next chapter, we will take a closer look at how to create and use variables.

What will be the output of the following code?

Select the correct answer

Everything was clear?

Section 1. Chapter 2
course content

Course Content

Introduction to TypeScript

SyntaxSyntax

TypeScript is an extension for JavaScript, and it is applied on top of this code. The basic syntax of JavaScript and TypeScript is identical, so if you already know the basics of JavaScript, you will find it much easier to understand this course. However, even in that case, I recommend you complete the tasks to review the fundamentals.

If you have never worked with JavaScript before - no problem. In this course, we will cover the basic syntax, which is the same for both TypeScript and JavaScript.

Let's start with printing text to the console:

To display information in the console, we use the following syntax:

Please note that the text we want to output to the console is enclosed in double-quotes (""). You can change the text in the code window above to experiment!

Note

Using a semicolon (;) at the end of a line in the code is optional.

With this command, you can also log anything on the console. Let's look at an example:

Note

We don't use double quotes ("") when printing numbers; double quotes are only used for text!

You can also combine numbers and text using template literals. This syntax is available in both TypeScript and JavaScript.

You should use backticks instead of double quotes. Also, you need to enclose values (numbers or variable names) in this syntax: ${variable/number}. Let's look at an example:

Note

var is a somewhat outdated way of declaring a variable. Nowadays, let is more commonly used for variable declaration, and const is used for declaring constants (variables that cannot be changed after initialization).

In the code example above, you can see how we created and used a variable. In the next chapter, we will take a closer look at how to create and use variables.

What will be the output of the following code?

Select the correct answer

Everything was clear?

Section 1. Chapter 2
some-alt