Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • TypeScript Tutorial
  • TS Exercise
  • TS Interview Questions
  • TS Cheat Sheet
  • TS Array
  • TS String
  • TS Object
  • TS Operators
  • TS Projects
  • TS Union Types
  • TS Function
  • TS Class
  • TS Generic
Open In App
Next Article:
TypeScript in operator narrowing Type
Next article icon

TypeScript Operators

Last Updated : 03 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

TypeScript operators are symbols or keywords that perform operations on one or more operands.

Below are the different TypeScript Operators:

Table of Content

  • TypeScript Arithmetic operators
  • TypeScript Logical operators
  • TypeScript Relational operators
  • TypeScript Bitwise operators
  • TypeScript Assignment operators
  • TypeScript Ternary/conditional operator
  • TypeScript Type Operators
  • TypeScript String Operators

TypeScript Arithmetic operators

In TypeScript, arithmetic operators are used to perform mathematical calculations.

Name

Description

Syntax

Addition(+)Adds two values or expressions.a + b
Subtraction(-)Subtracts the right operand from the left operand.a - b
Multiplication(*)Multiplies two values or expressionsa * b
Division(/)Divides the left operand by the right operand.a / b
Modulus(%)Returns the remainder of the division of the left operand by the right operand.a % b
Increment(++)Increase the value of the operand by 1.a++ or ++a
Decrement(--)Decrease the value of the operand by 1.a-- or --a

TypeScript Logical operators

In TypeScript, logical operators are used to perform logical operations on Boolean values.

Name

Description

Syntax

Logical AND (&&)

Returns true if both operands are true.

result = operand1 && operand2;

Logical OR (||)

Returns true if at least one of the operands is true.

result = operand1 || operand2;

Logical NOT (!)

Returns true if the operand is false, and vice versa.

result = !operand;

TypeScript Relational operators

In TypeScript, relational operators are used to compare two values and determine the relationship between them.

Name

Description

Syntax

Equal to (==)

Returns true if the values of the two operands are equal, after type coercion.

result = operand1 == operand2;

Not equal to (!=)

Returns true if the values of the two operands are not equal, after type coercion.

result = operand1 != operand2;

Strictly equal to (===)

Returns true if the values of the two operands are equal, without type coercion (strict equality).

result = operand1 === operand2;

Strictly not equal to (!==)

Returns true if the values of the two operands are not equal, without type coercion (strict inequality).

result = operand1 !== operand2;

Greater than (>)

Returns true if the value of the left operand is greater than the value of the right operand.

result = operand1 > operand2;

Less than (<)

Returns true if the value of the left operand is less than the value of the right operand.

result = operand1 < operand2;

Greater than or equal to (>=)

Returns true if the value of the left operand is greater than or equal to the value of the right operand.

result = operand1 >= operand2;

Less than or equal to (<=)

Returns true if the value of the left operand is less than or equal to the value of the right operand

result = operand1 <= operand2;

TypeScript Bitwise operators

In TypeScript, bitwise operators perform operations on the binary representation of numeric values.

Name

Description

Syntax

Bitwise AND (&)

Performs a bitwise AND operation between each pair of corresponding bits.

result = operand1 & operand2;

Bitwise OR (|)

Performs a bitwise OR operation between each pair of corresponding bits.

result = operand1 | operand2;

Bitwise XOR (^)

Performs a bitwise XOR (exclusive OR) operation between each pair of corresponding bits.

result = operand1 ^ operand2;

Bitwise NOT (~)

Inverts the bits of the operand, changing each 0 to 1 and each 1 to 0.

result = ~operand;

Left Shift (<<)

Shifts the bits of the left operand to the left by the number of positions specified by the right operand.

result = operand1 << operand2;

Sign-propagating Right Shift (>>)

Shifts the bits of the left operand to the right by the number of positions specified by the right operand, preserving the sign bit.

result = operand1 >> operand2;

Zero-fill Right Shift (>>>)

Shifts the bits of the left operand to the right by the number of positions specified by the right operand, filling the leftmost bits with zeros.

result = operand1 >>> operand2;

TypeScript Assignment operators

In TypeScript, assignment operators are used to assign values to variables and modify their values based on arithmetic or bitwise operations.

NameDescriptionSyntax
Assignment (=)Assigns the value of the right operand to the left operand.variable = value;
Addition Assignment (+=)Adds the value of the right operand to the current value of the left operand and assigns the result to the left operand.variable += value;
Subtraction Assignment (-=)Subtracts the value of the right operand from the current value of the left operand and assigns the result to the left operand.variable -= value;
Multiplication Assignment (*=)Multiplies the current value of the left operand by the value of the right operand and assigns the result to the left operand.variable *= value;
Division Assignment (/=)Divides the current value of the left operand by the value of the right operand and assigns the result to the left operand.variable /= value;
Modulus Assignment (%=)Calculates the remainder when dividing the current value of the left operand by the value of the right operand and assigns the result to the left operand.variable %= value;

TypeScript Ternary/conditional operator

In TypeScript, the ternary operator, also known as the conditional operator, is a concise way to write conditional statements. It allows you to express a simple if-else statement in a single line.

NameDescriptionSyntax
Ternary/Conditional OperatorEvaluates the condition. If true, returns expression_if_true; if false, returns expression_if_false.condition ? expression_if_true : expression_if_false;

TypeScript Type Operators

In TypeScript, type operators are constructs that allow you to perform operations on types. These operators provide powerful mechanisms for defining and manipulating types in a flexible and expressive manner.

NameDescriptionSyntax
typeofObtains the type of a variable, function, or property.let x = 10;<br>type XType = typeof x;<br>// XType is 'number'
keyofObtains the keys (property names) of a type.type Person = { name: string; age: number };<br>type PersonKeys = keyof Person;<br>`// PersonKeys is 'name'
Mapped TypesAllows creating new types based on the properties of existing types.type Optional<T> = { [K in keyof T]?: T[K] };
Conditional TypesAllows expressing a type based on a condition.type TypeName<T> = T extends string ? 'string' : 'non-string';

TypeScript String Operators

In TypeScript, string operators and features are used for manipulating and working with string values.

NameDescriptionSyntax
String Concatenation (+)Concatenates two strings.let fullName = firstName + " " + lastName;
Template Literals (`)Allows embedding expressions inside strings.let message = \I am ${age} years old.`;`
String InterpolationSimilar to template literals, it allows inserting variables into strings.let description = "I live in " + city + ".";
String MethodsVarious methods for manipulating strings.let substring = phrase.substring(7, 15);
String Length Property (length)Returns the length of a string.let length = message.length;

Next Article
TypeScript in operator narrowing Type

A

amanv09
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • TypeScript

Similar Reads

  • TypeScript Object
    A TypeScript object is a collection of key-value pairs, where keys are strings and values can be any data type. Objects in TypeScript can store various types, including primitives, arrays, and functions, providing a structured way to organize and manipulate data. What Are TypeScript Objects?An objec
    5 min read
  • Typescript Keyof Type Operator
    The TypeScript keyof operator is used to get a union of all keys in an object type. It’s useful when you want to work with the property names of an object in a type-safe way, ensuring only valid keys are used. We can use it to define generic functions that work with any object type, without knowing
    3 min read
  • PHP Operators
    In PHP, operators are special symbols used to perform operations on variables and values. Operators help you perform a variety of tasks, such as mathematical calculations, string manipulations, logical comparisons, and more. Understanding operators is essential for writing effective and efficient PH
    9 min read
  • TypeScript in operator narrowing Type
    In this article, we will learn about the 'in' operator narrowing Type in Typescript. In TypeScript, the 'in' operator is used to narrow or refine the type of an object within a conditional statement or block. It checks whether a specific property or key exists within an object, and if it does, it na
    3 min read
  • TypeScript Call Signatures
    TypeScript call signatures define the parameter types and return types for function-like objects, enabling the creation of callable entities with additional properties. Allow objects to be invoked as functions while possessing properties.Enhance code flexibility by combining callable behavior with s
    3 min read
  • Data types in TypeScript
    In TypeScript, a data type defines the kind of values a variable can hold, ensuring type safety and enhancing code clarity. Primitive Types: Basic types like number, string, boolean, null, undefined, and symbol.Object Types: Complex structures including arrays, classes, interfaces, and functions.Pri
    3 min read
  • TypeScript Utility Types
    TypeScript utility types are predefined constructs that facilitate common type transformations, enhancing code flexibility and maintainability. They allow developers to modify existing types easily, such as by making properties optional or read-only.Utility types help in creating more expressive and
    5 min read
  • TypeScript Programming Example
    TypeScript is a popular superset of JavaScript that adds static typing and other features to improve the development experience. In this blog post, we’ll explore practical examples of TypeScript that demonstrate how it can be used to solve common development challenges. Tip: Before, directly jumping
    12 min read
  • TypeScript Assertion functions
    TypeScript Assertion functions are nothing but the functions that allow us to mainly create the custom type guards that assert the type of a value on our specific criteria. The most suitable use of Assertion Functions is when we are working with the more complex data structures. Syntax:function asse
    3 min read
  • TypeScript Conditional Types
    In TypeScript, conditional types enable developers to create types that depend on a condition, allowing for more dynamic and flexible type definitions. They follow the syntax T extends U ? X : Y, meaning if type T is assignable to type U, the type resolves to X; otherwise, it resolves to Y.Condition
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences