---
title: "Operators in AngularJS"  
description: "These operators are similar to those found in JavaScript and can be used to perform arithmetic, logical, and comparison operations within AngularJS ex"  
author: "Ravi Vishwakarma"  
published: 2024-06-24  
updated: 2024-06-24  
canonical: https://www.mindstick.com/articles/336199/operators-in-angularjs  
category: "angular js"  
tags: ["web development", "angular js", "front-end development"]  
reading_time: 4 minutes  

---

# Operators in AngularJS

#### Operators in AngularJS Expressions

In AngularJS, expressions can include various operators to perform calculations and [manipulate data](https://www.mindstick.com/forum/157877/how-do-you-use-filters-in-angularjs-to-manipulate-data). These operators are similar to those found in [JavaScript](https://www.mindstick.com/forum/12869/how-to-c-sharp-and-javascript-email-validation-regex) and can be used to perform **arithmetic**, **logical**, and **comparison operations** within AngularJS expressions.

#### Arithmetic Operators

[Arithmetic operators](https://www.mindstick.com/forum/157625/what-is-meant-by-arithmetic-operators-in-python) are used to perform mathematical calculations.

| **Operator** | **Description** | **Example** | **Result** |
| --- | --- | --- | --- |
| `+` | Adds two numbers | `{{ 5 + 5 }}` | `10` |
| `-` | Subtracts one number from another | `{{ 10 - 5 }}` | `5` |
| `*` | Multiplies two numbers | `{{ 4 * 3 }}` | `12` |
| `/` | Divides one number by another | `{{ 20 / 4 }}` | `5` |
| `%` | Returns the remainder of a division | `{{ 10 % 3 }}` | `1` |

#### Comparison Operators

Comparison operators are used to [compare two](https://answers.mindstick.com/qa/36815/how-do-i-compare-two-photos-to-see-if-they-are-the-same-person) values.

| **Operator** | **Description** | **Example** | **Result** |
| --- | --- | --- | --- |
| `==` | Checks if two values are equal | `{{ 5 == 5 }}` | `true` |
| `!=` | Checks if two values are not equal | `{{ 5 != 4 }}` | `true` |
| `===` | Checks if two values are equal and of the same type | `{{ 5 === '5' }}` | `false` |
| `!==` | Checks if two values are not equal and/or not of the same type | `{{ 5 !== '5' }}` | `true` |
| `>` | Checks if one value is greater than another | `{{ 10 > 5 }}` | `true` |
| `>=` | Checks if one value is greater than or equal to another | `{{ 10 >= 10 }}` | `true` |
| `<` | Checks if one value is less than another | `{{ 5 < 10 }}` | `true` |
| `<=` | Checks if one value is less than or equal to another | `{{ 5 <= 5 }}` | `true` |

#### Logical Operators

Logical operators are used to combine or negate expressions.

| **Operator** | **Description** | **Example** | **Result** |
| --- | --- | --- | --- |
| `&&` | Returns true if both expressions are true | `{{ true && false }}` | `false` |
| `!` | Negates an [expression](https://www.mindstick.com/articles/1861/sqlite-expressions) | `{{ !true }}` | `false` |

#### Ternary Operator

The [ternary operator](https://answers.mindstick.com/qa/104753/define-ternary-operator) is used to perform conditional evaluations.

| **Operator** | **Description** | **Example** | **Result** |
| --- | --- | --- | --- |
| `condition ? trueExpression : falseExpression` | Evaluates a condition and returns one of two values based on whether the condition is [true or false](https://www.mindstick.com/forum/160329/how-can-you-convert-a-value-to-a-boolean-true-or-false-in-javascript) | `{{ isTrue ? 'Yes' : 'No' }}` | `Yes` if `isTrue` is true, otherwise `No` |

## Example of Operators in AngularJS

```html
<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.8.2/angular.min.js"></script>
    <script>
        var app = angular.module('myApp', []);
        app.controller('myCtrl', function($scope) {
            $scope.a = 5;
            $scope.b = 10;
            $scope.isTrue = true;
        });
    </script>
</head>
<body ng-app="myApp" ng-controller="myCtrl">

    <h2>Arithmetic Operators</h2>
    <table border="1">
        <tr><th>Expression</th><th>Result</th></tr>
        <tr><td>{{ a + b }}</td><td>15</td></tr>
        <tr><td>{{ a - b }}</td><td>-5</td></tr>
        <tr><td>{{ a * b }}</td><td>50</td></tr>
        <tr><td>{{ a / b }}</td><td>0.5</td></tr>
        <tr><td>{{ a % b }}</td><td>5</td></tr>
    </table>

    <h2>Comparison Operators</h2>
    <table border="1">
        <tr><th>Expression</th><th>Result</th></tr>
        <tr><td>{{ a == b }}</td><td>false</td></tr>
        <tr><td>{{ a != b }}</td><td>true</td></tr>
        <tr><td>{{ a === b }}</td><td>false</td></tr>
        <tr><td>{{ a !== b }}</td><td>true</td></tr>
        <tr><td>{{ a > b }}</td><td>false</td></tr>
        <tr><td>{{ a >= b }}</td><td>false</td></tr>
        <tr><td>{{ a < b }}</td><td>true</td></tr>
        <tr><td>{{ a <= b }}</td><td>true</td></tr>
    </table>

    <h2>Logical Operators</h2>
    <table border="1">
        <tr><th>Expression</th><th>Result</th></tr>
        <tr><td>{{ isTrue && false }}</td><td>false</td></tr>
        <tr><td>{{ isTrue || false }}</td><td>true</td></tr>
        <tr><td>{{ !isTrue }}</td><td>false</td></tr>
    </table>

    <h2>Ternary Operator</h2>
    <table border="1">
        <tr><th>Expression</th><th>Result</th></tr>
        <tr><td>{{ isTrue ? 'Yes' : 'No' }}</td><td>Yes</td></tr>
    </table>

</body>
</html>
```

Operators in AngularJS expressions allow for powerful and flexible data [manipulation](https://www.mindstick.com/forum/34588/list-manipulation) directly within the view templates, enhancing the [functionality](https://www.mindstick.com/interview/547/explain-about-the-functionality-of-vb-script) and interactivity of AngularJS applications.

---

Original Source: https://www.mindstick.com/articles/336199/operators-in-angularjs

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
