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
course content

Conteúdo do Curso

Introduction to TypeScript

Introduction to TypeScript

1. TypeScript Fundamentals
2. Conditional Statements
3. Arrays
4. Loops
5. Functions

bookSyntax

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:

1
console.log("Hello World");
copy

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:

12
console.log("Any custom text you like") console.log(12345)
copy

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:

12
var variable = 15 console.log(`There is two numbers: ${variable} and ${13}`)
copy

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?

What will be the output of the following code?

Selecione a resposta correta

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 1. Capítulo 2
some-alt