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

Зміст курсу

Introduction to TypeScript

Introduction to TypeScript

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

book
Functions introduction

Functions are what TypeScript is made of. When you write large advanced programs or applications, it's advisable to organize all your code into functions. Let's look at what a function is and its syntax:

To declare a function, you just need to write function, followed by the function name and parentheses (). Then, you open curly braces, which will contain the function body. Inside the function body, you specify what your function will do. In the example above, the function prints a greeting to the console. Let's call the function and see how it works:

1234
function greeting() { console.log("Hello there!"); } greeting()
copy

To call a function, all we need to do is write it in the code, and the function will do its job. We can call it many times in a row or even within loops, for example:

1234567
function greeting() { console.log("Hello there!"); } for (let i = 0; i < 3; i++) { greeting() }
copy

Instead of writing code each time to display a message in the console, we simply call the greeting function.

Of course, this is the simplest example of a function. Functions have virtually limitless capabilities. You can encapsulate complex algorithms within a single function. You can use functions within functions and much more. In this section, we'll explore the fundamental techniques of working with functions, including passing parameters and returning values from functions. This is where real programming begins!

Why are functions used in TypeScript?

Why are functions used in TypeScript?

Виберіть правильну відповідь

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 5. Розділ 1
We're sorry to hear that something went wrong. What happened?
some-alt