TypeScript Operators Last Updated : 07 Aug, 2025 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 operatorsTypeScript Logical operatorsTypeScript Relational operatorsTypeScript Bitwise operatorsTypeScript Assignment operatorsTypeScript Ternary/conditional operatorTypeScript Type OperatorsTypeScript String OperatorsTypeScript Arithmetic operatorsIn TypeScript, arithmetic operators are used to perform mathematical calculations. NameDescriptionSyntaxAddition(+)Adds two values or expressions.a + bSubtraction(-)Subtracts the right operand from the left operand.a - bMultiplication(*)Multiplies two values or expressionsa * bDivision(/)Divides the left operand by the right operand.a / bModulus(%)Returns the remainder of the division of the left operand by the right operand.a % bIncrement(++)Increase the value of the operand by 1.a++ or ++aDecrement(--)Decrease the value of the operand by 1.a-- or --aTypeScript Logical operatorsIn TypeScript, logical operators are used to perform logical operations on Boolean values.Name DescriptionSyntaxLogical 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 operatorsIn TypeScript, relational operators are used to compare two values and determine the relationship between them.Name DescriptionSyntaxEqual 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 operandresult = operand1 <= operand2;TypeScript Bitwise operatorsIn TypeScript, bitwise operators perform operations on the binary representation of numeric values.NameDescriptionSyntaxBitwise 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 operatorsIn TypeScript, assignment operators are used to assign values to variables and modify their values based on arithmetic or bitwise operations. NameDescriptionSyntaxAssignment (=)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 operatorIn 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. NameDescriptionSyntaxTernary/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 OperatorsIn 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.NameDescriptionSyntaxtypeofObtains 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 OperatorsIn TypeScript, string operators and features are used for manipulating and working with string values. NameDescriptionSyntaxString 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; Comment More infoAdvertise with us A amanv09 Follow Improve Article Tags : TypeScript Similar Reads TypeScript Tutorial TypeScript is a superset of JavaScript that adds extra features like static typing, interfaces, enums, and more. Essentially, TypeScript is JavaScript with additional syntax for defining types, making it a powerful tool for building scalable and maintainable applications.Static typing allows you to 8 min read TypeScript BasicsIntroduction to TypeScriptTypeScript is a syntactic superset of JavaScript that adds optional static typing, making it easier to write and maintain large-scale applications.Allows developers to catch errors during development rather than at runtime, improving code reliability.Enhances code readability and maintainability wit 5 min read Difference between TypeScript and JavaScriptEver wondered about the difference between JavaScript and TypeScript? If you're into web development, knowing these two languages is super important. They might seem alike, but they're actually pretty different and can affect how you code and build stuff online.In this article, we'll break down the 4 min read How to install TypeScript ?TypeScript is a powerful language that enhances JavaScript by adding static type checking, enabling developers to catch errors during development rather than at runtime. As a strict superset of JavaScript, TypeScript allows you to write plain JavaScript with optional extra features. This guide will 3 min read Hello World in TypeScriptTypeScript is an open-source programming language. It is developed and maintained by Microsoft. TypeScript follows javascript syntactically but adds more features to it. It is a superset of javascript. The diagram below depicts the relationship:Typescript is purely object-oriented with features like 3 min read How to execute TypeScript file using command line?TypeScript is a statically-typed superset of JavaScript that adds optional type annotations and compiles to plain JavaScript. It helps catch errors during development. To execute a TypeScript file from the command line, compile it using tsc filename.ts, then run the output JavaScript file with node. 2 min read Variables in TypeScriptIn TypeScript, variables are used to store values that can be referenced and manipulated throughout your code. TypeScript offers three main ways to declare variables: let, const, and var. Each has different behavior when it comes to reassigning values and scoping, allowing us to write more reliable 6 min read What are the different keywords to declare variables in TypeScript ?Typescript variable declarations are similar to Javascript. Each keyword has a specific scope. Let's learn about variable declarations in this article. In Typescript variables can be declared by using the following keywords:varlet constVar keyword: Declaring a variable using the var keyword.var vari 4 min read Identifiers and Keywords in TypeScriptIn TypeScript, identifiers are names used for variables, classes, or methods and must follow specific naming rules. Keywords are reserved words with predefined meanings and cannot be used as identifiers. Comments, both single-line and multi-line, enhance code readability and are ignored during code 2 min read TypeScript primitive typesData types in TypeScriptIn 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.Prim 3 min read TypeScript NumbersTypeScript Numbers refer to the numerical data type in TypeScript, encompassing integers and floating-point values. The Number class in TypeScript provides methods and properties for manipulating these values, allowing for precise arithmetic operations and formatting, enhancing JavaScript's native n 4 min read TypeScript StringIn TypeScript, the string is sequence of char values and also considered as an object. It is a type of primitive data type that is used to store text data. The string values are used between single quotation marks or double quotation marks, and also array of characters works same as a string. TypeSc 4 min read Explain the concept of null and its uses in TypeScriptNull refers to a value that is either empty or a value that doesn't exist. It's on purpose that there's no value here. TypeScript does not make a variable null by default. By default unassigned variables or variables which are declared without being initialized are 'undefined'. To make a variable nu 3 min read TypeScript Object typesWhat are TypeScript Interfaces?TypeScript interfaces define the structure of objects by specifying property types and method signatures, ensuring consistent shapes and enhancing code clarity.Allow for optional and read-only properties for flexibility and immutability.Enable interface inheritance to create reusable and extendable 4 min read TypeScript classA TypeScript class is a blueprint for creating objects, encapsulating properties (data) and methods (behavior) to promote organization, reusability, and readability.Supports inheritance, allowing one class to extend another and reuse functionality.Provides access modifiers (public, private, protecte 4 min read How enums works in TypeScript ?In this article, we will try to understand all the facts which are associated with enums in TypeScript. TypeScript enum: TypeScript enums allow us to define or declare a set of named constants i.e. a collection of related values which could either be in the form of a string or number or any other da 4 min read TypeScript TuplesIn JavaScript, arrays consist of values of the same type, but sometimes we need to store a collection of values of different types in a single variable. TypeScript offers tuples for this purpose. Tuples are similar to structures in C programming and can be passed as parameters in function calls.Tupl 3 min read TypeScript other typesWhat is any type, and when to use it in TypeScript ?Any is a data type in TypeScript. Any type is used when we deal with third-party programs and expect any variable but we don't know the exact type of variable. Any data type is used because it helps in opt-in and opt-out of type checking during compilation. In this article, we will see what is any 3 min read How to Create an Object in TypeScript?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.Creating Objects in TypescriptNow, let 4 min read What is an unknown type and when to use it in TypeScript ?In Typescript, any value can be assigned to unknown, but without a type assertion, unknown can't be assigned to anything but itself and any. Similarly, no operations on an unknown are allowed without first asserting or restricting it down to a more precise type.  similar to any, we can assign any va 3 min read Explain the purpose of never type in TypeScriptIn Typescript when we are certain that a particular situation will never happen, we use the never type. For example, suppose you construct a function that never returns or always throws an exception then we can use the never type on that function. Never is a new type in TypeScript that denotes value 3 min read TypeScript combining typesTypeScript UnionThe TypeScript union has the ability to combine one or two different types of data (i.e., number, string, float, double, etc). It is the most powerful way to express a variable with multiple types. Use pipe ('|') symbol to combine two or more data types to achieve Union type. Syntax: (type1|type2|ty 3 min read What are type aliases and how to create it in Typescript ?In Typescript, Type aliases give a type a new name. They are similar to interfaces in that they can be used to name primitives and any other kinds that you'd have to define by hand otherwise. Aliasing doesn't truly create a new type; instead, it gives that type a new name. Aliasing a primitive isn't 3 min read TypeScript AssertionsExplain Type assertions in TypeScriptIn TypeScript, type assertions allow developers to override the compiler's inferred type, informing it of the specific type of a value. Type assertions are purely compile-time constructs and do not alter the runtime behavior of the code. They are particularly useful when interfacing with APIs or thi 3 min read TypeScript FunctionsHow to write a function in Typescript ?Writing a function in TypeScript is similar to writing it in JavaScript but with added parameters and return type. Note that any JavaScript function is a perfectly valid TypeScript function. However, we can do better by adding type.Syntax: Let's see a basic TypeScript function syntax (with two argum 4 min read How to achieve function overloading in TypeScript ?In this article, we will try to understand some basic details which are associated with the concept of function/method overloading, further will see how we could implement function overloading in TypeScript. Let us first understand some basic facts involved in function/method Overloading. Function/M 2 min read Explain the arrow function syntax in TypeScriptArrow functions in TypeScript are implemented similarly to JavaScript (ES6). The main addition in TypeScript is the inclusion of data types or return types in the function syntax, along with the types for the arguments passed into the function.What is arrow function syntax in TypeScript?Arrow functi 3 min read TypeScript toPrecision() FunctionThe toPrecision() method is used to return the string representation in exponential or fixed-point to the specified precision. Syntax:number.toPrecision( [ precision ] )Parameters:It represents an integer value specifying the number of significant digits. Return Value:The toPrecision() method in Typ 1 min read TypeScript toFixed() FunctionThe toFixed() function in TypeScript formats a number using fixed-point notation, specifying the number of digits after the decimal point. It returns a string representation of the number, ensuring precise control over its decimal places for consistent numerical formatting.Syntaxnumber.toFixed( [dig 2 min read TypeScript toLocaleString() FunctionThe toLocaleString() function in TypeScript converts a number to a locale-specific string representation. It optionally accepts locale and formatting options to customize the output, such as currency or decimal precision, ensuring numbers are formatted according to regional conventions.Syntaxnumber. 2 min read TypeScript toString()The toString() method in TypeScript is used to return a string representing the specified object radix (base). Syntax:number.toString( [radix] )Parameters:This function accepts a single parameter as mentioned above and described below.radix: This parameter represents an integer between 2 and 36 spec 1 min read TypeScript interfaces and aliasesWhat are TypeScript Interfaces?TypeScript interfaces define the structure of objects by specifying property types and method signatures, ensuring consistent shapes and enhancing code clarity.Allow for optional and read-only properties for flexibility and immutability.Enable interface inheritance to create reusable and extendable 4 min read What are type aliases and how to create it in Typescript ?In Typescript, Type aliases give a type a new name. They are similar to interfaces in that they can be used to name primitives and any other kinds that you'd have to define by hand otherwise. Aliasing doesn't truly create a new type; instead, it gives that type a new name. Aliasing a primitive isn't 3 min read TypeScript classesHow to Extend an Interface from a class in TypeScript ?In this article, we will try to understand how we to extend an interface from a class in TypeScript with the help of certain coding examples. Let us first quickly understand how we can create a class as well as an interface in TypeScript using the following mentioned syntaxes: Syntax: This is the s 3 min read How to Create an Object in TypeScript?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.Creating Objects in TypescriptNow, let 4 min read How to use getters/setters in TypeScript ?In TypeScript, getters and setters provide controlled access to class properties, enhancing encapsulation and flexibility.Getters allow you to retrieve the value of a property with controlled logic.Setters enable controlled assignment to properties, often including validation or transformations.Java 5 min read TypeScript InheritanceInheritance is a fundamental concept in object-oriented programming (OOP). It allows one class to inherit properties and methods from another class. The class that inherits is called the child class, and the class whose properties and methods are inherited is called the parent class. Inheritance ena 3 min read When to use interfaces and when to use classes in TypeScript ?TypeScript supports object-oriented programming features like classes and interfaces etc. classes are the skeletons for the object. it encapsulates the data which is used in objects. Interfaces are just like types for classes in TypeScript. It is used for type checking. It only contains the declarat 4 min read Generics Interface in typescript"A major part of software engineering is building components that not only have well-defined and consistent APIs but are also reusable. " This sentence is in the official documentation we would start with. There are languages that are strong in static typing & others that are weak in dynamic typ 5 min read How to use property decorators in TypeScript ?Decorators are a way of wrapping an existing piece of code with desired values and functionality to create a new modified version of it. Currently, it is supported only for a class and its components as mentioned below: Class itselfClass MethodClass PropertyObject Accessor ( Getter And Setter ) Of C 4 min read Like