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

book
Summary

Congratulations!

You've taken a small step for a person but a giant leap for your successful career! You've successfully completed the beginner course on TypeScript, and that's commendable. If you've tackled all the tasks and studied the theory, you're doing great! But if you skipped chapters just to get the certificate, well, that's your problem.

Let's summarize the entire beginner course, what TypeScript is, and why it's essential. We'll revisit the basic syntax, TypeScript's advantages, and much more.

Overall

TypeScript is a general purpose programming language that serves as a superset of JavaScript. TypeScript stands out with its static typing, error highlighting during the coding phase, object-oriented programming features, and many other improvements compared to JavaScript.

TypeScript is beloved and widely used. It's the go-to choice for front-end development in many prominent companies and is a key component in various popular frameworks. The simplest example is Angular.

Syntax

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

javascript
console.log("Text we want to output");

If we want to declare a variable without any type, we can use the following syntax:

javascript
let name = value;

Typed variable:

typescript
let name: type = value;

One-line comment:

javascript
// commented fragment

Multi-line comment:

javascript
/* multi-line
fragment */

Conditional Statements

Syntax of the if statement:

javascript
if (condition) {
// code to be executed if the condition is true
}

condition must have a boolean type!

if-else statement:

javascript
if (first_condition) {
// code block if the first condition is true
} else if (second_condition) {
/* A block of code that will execute
if the first condition is false
and the second condition is true. */
} else {
/* A block of code that will execute
if all previous conditions are false.
}

Switch-case:

javascript
switch (expression) {
case value1:
// Code to be execute if expression equals value1
break;
case value2:
// Code to execute if expresson equals value2
break;
// Additional cases...

default:
/* Code to execute if none of the cases
match the expression
}

Arrays

Declaring array:

javascript
let name[]: type[] = [element1, elememt2, ... , elementN];

Zero-based indexing:

javascript
[0, 1, 2, ..., n];

It means that the first element in the array will have an index 0, the second element will have an index 1, and so on.

You can get the element from the array using it's index:

javascript
var element = array[index];

You can also modify the array's elements using their indexes:

javascript
array[index] = value;

You can explore array methods in this chapter: Working with Array Elements

Loops

while-loop syntax:

javascript
while (condition) {
// The code that the loop will execute
// while the condition is `true`
}

The keyword break is used to immediately stop the execution of a loop.

do-while loop syntax:

javascript
do {
// The code that the loop will execute
// while the condition is `true`
} while (condition)

The do-while loop will execute at least once.

for loop syntax:

javascript
for (initialization; condition; increment/decrement) {
// Code to be executed in each iteration
}

Functions

Functions syntax:

javascript
function name(parameter: type, optionalParameter?: type, defaultParameter: type = value) : returnType {
// reusable code block
}

How to call a function?

javascript
functionName(parameters);

These are the basic concepts and syntax you've covered in this course.

From this point on, you have a foundation in TypeScript, and you can write simple programs and functions. In future courses, you will learn more advanced topics, such as object-oriented programming, classes, objects, anonymous functions, and much more.

Now, I want to congratulate you once again and wish you a well-deserved rest. You've done great!

question mark

Are you satisfied with your work?

Select the correct answer

Was alles duidelijk?

Hoe kunnen we het verbeteren?

Bedankt voor je feedback!

Sectie 5. Hoofdstuk 7

Vraag AI

expand

Vraag AI

ChatGPT

Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.

We use cookies to make your experience better!
some-alt