Skip to main content

compare

import NodeTypeBadge from '@site/src/components/DocsFeatures/node-type-badge';

# Compare

<NodeTypeBadge type="uncontrolled" />

## Overview
The Compare node evaluates a comparison between two input values and outputs a boolean result. It supports standard comparison operators including less than, greater than, and equality checks. This node is useful for creating conditional logic in workflows, filtering data, or validating that values meet specific criteria.

The node performs loose comparisons (using JavaScript's `==` operator for equality), allowing you to compare numbers, strings, or mixed types where applicable.

## Inputs
| Input | Type | Description | Default |
| :--- | :--- | :--- | :--- |
| **a** | Text | The first value to compare. | - |
| **b** | Text | The second value to compare. | - |
| **Operation** | Enum | The comparison operator to use. Options: `a < b`, `a <= b`, `a == b`, `a >= b`, `a > b`. | `a == b` |

## Outputs
| Output | Type | Description |
| :--- | :--- | :--- |
| **Result** | Boolean | `true` if the comparison condition is met, `false` otherwise. |

## Runtime Behavior and Defaults
The Compare node is an **uncontrolled** node, meaning it executes automatically whenever either input `a` or `b` changes. It does not require an event trigger to run.

- **Default Operation**: The node defaults to equality comparison (`==`) if no operation is specified.
- **Comparison Logic**:
- For numeric comparisons, standard arithmetic comparison is used.
- For string comparisons, lexicographic (alphabetical) ordering is used.
- Mixed type comparisons follow JavaScript's loose equality rules.
- **Output**: The `result` output always contains a boolean value (`true` or `false`). If an unrecognized operation is specified, the node returns `false` by default.

## Example Usage
**Scenario**: Check if a user's score is greater than or equal to a passing threshold.

1. Connect a **Number** node (or any data source) outputting the user's score to input `a`.
2. Connect another **Number** node with the value `70` (the passing threshold) to input `b`.
3. Set the **Operation** property to `a >= b`.
4. Connect the **Result** output to an **If** node's `test` input to branch the workflow based on whether the user passed.

**Alternative**: To check if two values are exactly equal (useful for validation), leave the operation as `a == b` and connect the values you want to compare to inputs `a` and `b`.