Getting to Know Commonly Used TypeScript Operators

24 Jun 2023 Balmiki Mandal 0 Typescript

Commonly Used TypeScript Operators

TypeScript is a popular typed superset of JavaScript that compiles to plain JavaScript. It adds optional static typing and class-based object-oriented programming to the language. TypeScript is used by many developers all over the world and in order to work with it effectively, it’s important to understand its operators. In this article, we’ll take a look at some of the most commonly used TypeScript operators.

Arithmetic operators

Arithmetic operators are used to perform mathematical operations like addition, subtraction, multiplication, etc. The available arithmetic operators in TypeScript are:

  • Addition (+)
  • Subtraction (-)
  • Multiplication (*)
  • Division (/)
  • Modulus (%)
  • Increment (++)
  • Decrement (--)

Assignment operators

Assignment operators are used to assign values to variables. The available assignment operators in TypeScript are:

  • Equal (=)
  • Add and assign (+=)
  • Subtract and assign (-=)
  • Multiply and assign (*=)
  • Divide and assign (/=)
  • Modulus and assign (%=)

Comparison operators

Comparison operators are used to compare two values. The available comparison operators in TypeScript are:

  • Equal (==)
  • Not equal (!=)
  • Strict equal (===)
  • Strict not equal (!==)
  • Greater than (>)
  • Less than (<)
  • Greater than or equal (>=)
  • Less than or equal (<=)

Logical operators

Logical operators are used to combine and manipulate one or more boolean expressions. The available logical operators in TypeScript are:

  • Logical AND (&&)
  • Logical OR (||)
  • Logical NOT (!)

Conditional operator (ternary operator)

The conditional operator is a shorthand way of writing an if-else statement. Syntax wise, it looks like this: [condition] ? [expression1] : [expression2];. This operator evaluates the condition first and if it’s true, it returns expression1, otherwise it returns expression2.

Bitwise operators

Bitwise operators are used to manipulate individual bits in a value. The available bitwise operators in TypeScript are:

  • AND (&)
  • OR (|)
  • XOR (^)
  • NOT (~)
  • Left shift (<<)
  • Right shift (>>)
  • Zero-fill Right shift (>>>)

These are some of the most commonly used TypeScript operators. While it’s not necessary to know all of them in detail, having a basic understanding will help you become a better TypeScript developer.

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.