Зміст курсу
Introduction to TypeScript
Introduction to TypeScript
Simple variable declaration
Variables greatly simplify the lives of all developers. You can store text, numbers, or a boolean value (true
or false
) in a variable. Let's look at the syntax for creating a variable and displaying it in the console:
let text = "Hello World!" let number = 12345 let boolean = true console.log(`First variable: ${text}, second variable: ${number}, third: ${boolean}`)
As you can see, the syntax for declaring a variable looks like this:
Also, note that when we use the let
keyword to declare a variable, both TypeScript and JavaScript automatically determine what type this variable should be. TypeScript allows you to specify the data type of a variable (that's why it's called TypeScript), which I will tell you about later in this course. For now, let's focus on simple variable declarations.
Note
Remember that we use
let
andconst
instead ofvar
. For now, the examples will still includevar
because it's the older way of declaring variables in TypeScript and JavaScript that has been around for a long time. Later on, we will explore the newer ways of declaring variables.
Arithmetic Operations in TypeScript
TypeScript, like any other programming language, supports simple and complex mathematical operations. Let's take a look at basic operations:
- Addition (
+
): Adds two numbers:
let sum = 5 + 3; console.log(sum)
- Subtraction (
-
): Subtracts one number from another:
let difference = 10 - 4; console.log(difference)
- Multiplication (
*
): Multiplies two numbers:
let product = 6 * 7; console.log(product)
- Division (
/
): Divides one number by another:
let quotient = 20 / 4; console.log(quotient)
- Modulus (
%
): Returns the remainder of the division:
let remainder = 15 % 4; console.log(remainder)
- Exponentiation (
**
orMath.pow()
):** Raises a number to a power:
let power = 2 ** 3; console.log(power)
Phew, I hope, I've listed everything. This is a list of the most commonly used arithmetic operations in TypeScript. I'll tell you how to use these operations in the next chapter, where you'll learn how to use them correctly and what you can achieve with their help.
Дякуємо за ваш відгук!