1.
Introduction
2.
Arithmetic operators
3.
Logical operators
4.
Relational operators
5.
Bitwise operators
6.
Assignment operators
7.
Conditional operator
8.
Type Operator
9.
FAQs
10.
Key Takeaways
Last Updated: Mar 27, 2024

# Typescript Operators

Parth
0 upvote

## Introduction

In a calculator, we operate with two or more numbers by adding, subtracting, multiplying, or dividing the operands (numbers). The goal is to operate on the numbers to obtain a specific result. It is crucial to understand the fundamental operators provided to perform operations in programming.

An operator is a symbol that is responsible for performing operations.

As an example, let us consider the expression,

5+20=25

In this case, the numbers 5 and 20 are operands, and the symbols and are called operators. The + operator is one of the many operators available in Typescript.

Let us dive deeper into the types of operators:

• Arithmetic operators
• Logical operators
• Relational operators
• Bitwise operators
• Assignment operators
• Ternary/conditional operator
• Type Operator

## Arithmetic operators

The arithmetic operator is responsible for performing arithmetical operations. It takes numerical values as input, operates on them, and returns the output as a single value

## Logical operators

The logical operator is responsible for performing logical operations. It implements logical conditions on two or more operands and returns either True or False.

## Relational operators

The relational operator defines a relation between two or more operands. After performing relational operations, these operators return either true or false Boolean values.

Let us assume that A’s value is 5 and B’s is 15.

## Bitwise operators

The Bitwise operator is responsible for performing Bit-related computations. As every number in programming is composed of a set of 0s and 1s, the actions performed with these bits is possible with Bitwise Operators.,

Let us assume the variable A = 2 and B = 3

LSB=Least Significant Bit

MSB=Most Significant Bit

## Assignment operators

The assignment operator is responsible for assigning values to a variable.

## Conditional operator

The conditional operator is beneficial as it drastically reduces the code line.

Instead of using an if-else statement, we can use Conditional operator syntax.

Syntax

``condition ? expression1 : expression2;``

If the given condition is true,expression1 is executed. Else,expression2 executes.

``````let isAdult = true;
let message = isValid ? 'Welcome' : 'Underage please exit';
console.log(message)                   //'Welcome”``````

## Type Operator

The type operator returns the data type of the input variable.

``````console.log(typeof 60) // number
console.log(typeof "Ninja") // string
console.log(typeof true) // boolean
console.log(typeof Math.round) // function
console.log(typeof undefined) // undefined
console.log(typeof null) // object``````

## FAQs

1. What is a TypeScript operator?
An operator is a symbol that uses operands as inputs and performs operations. Then, it returns a value that is either a number or boolean. All Javascript operators are present in Typescript.

2. What is Nullish coalescing operator?
The Nullish coalescing operator is a logical operator that returns the right operand in case the given left operand is undefined. Otherwise, it returns the left operand. It is represented by the symbol (??)

## Key Takeaways

From this article, we learned about Typescript's various operators and how their syntaxes are used. We also learned the key differences between the logical and bitwise operators. We looked into how conditional operators make writing if-else statements simple.

However, this isn't enough, as there is always much more to explore and learn about this vast field of Web Development. To know more about Typescript and its intricacies, check out the articles on Typescript or enroll in our highly curated Web Development course.