Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Simple variable declaration | TypeScript Fundamentals
course content

Course Content

Introduction to TypeScript

Simple variable declarationSimple variable declaration

A variable is a container that holds some data. You can write and modify data in a variable, and use that variable wherever it's needed.

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:

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 and const instead of var. For now, the examples will still include var 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:
  • Subtraction (-): Subtracts one number from another:
  • Multiplication (*): Multiplies two numbers:
  • Division (/): Divides one number by another:
  • Modulus (%): Returns the remainder of the division:
  • Exponentiation ( ** or Math.pow()):** Raises a number to a 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.

1. What will be the output of the following code?
2. How to declare a variable in TypeScript?

What will be the output of the following code?

Select the correct answer

question-icon

How to declare a variable in TypeScript?

Select a few correct answers

Everything was clear?

Section 1. Chapter 3
course content

Course Content

Introduction to TypeScript

Simple variable declarationSimple variable declaration

A variable is a container that holds some data. You can write and modify data in a variable, and use that variable wherever it's needed.

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:

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 and const instead of var. For now, the examples will still include var 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:
  • Subtraction (-): Subtracts one number from another:
  • Multiplication (*): Multiplies two numbers:
  • Division (/): Divides one number by another:
  • Modulus (%): Returns the remainder of the division:
  • Exponentiation ( ** or Math.pow()):** Raises a number to a 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.

1. What will be the output of the following code?
2. How to declare a variable in TypeScript?

What will be the output of the following code?

Select the correct answer

question-icon

How to declare a variable in TypeScript?

Select a few correct answers

Everything was clear?

Section 1. Chapter 3
some-alt