Зміст курсу
Introduction to TypeScript
Introduction to TypeScript
Syntax
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:
console.log("Hello World");
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:
console.log("Any custom text you like") console.log(12345)
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:
var variable = 15 console.log(`There is two numbers: ${variable} and ${13}`)
Note
var
is a somewhat outdated way of declaring a variable. Nowadays,let
is more commonly used for variable declaration, andconst
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.
Дякуємо за ваш відгук!