---
schema_version: "1"
id: 3e6b660fb71d50c890e07610713b24993ca0a0aa487f4b7df8e7e9c056662d36
title: "Handlebars Helper Function: compare"
collection: developer
version: current
locale: en-us
portal_url: https://docs.salesforce.com/developer/current/en-us/marketing-cloud/handlebars/reference/comparison/mcn-handlebars-reference-comparison-compare.md
canonical_url: https://developer.salesforce.com/docs/marketing/handlebars-for-marketing-cloud-next/references/mcn-handlebars-comparison-references/mcn-handlebars-reference-comparison-compare.html
source_site: developer.salesforce.com
content_type: documentation
content_hash: bf2da69cfd26e076e45df803d64105cdc28e33a7f904f5c4be9d3221b821aaed
products:
  - Handlebars for Marketing Cloud Next
  - Marketing Cloud
---
# Handlebars Helper Function: compare

Compares two values using a specified operator. The operation supports both numeric and string comparisons, and automatically determines the appropriate comparison type.

## Availability

This helper is available in the Winter ’26 release of Marketing Cloud Next.

## Syntax

```
{{compare leftValue operator rightValue}}
```

## Parameters

| Parameter    | Type   | Description                                                                                                                                                                                                                                                                                                                            |
| ------------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `leftValue`  | Any    | Required. The left operand for comparison                                                                                                                                                                                                                                                                                              |
| `operator`   | String | Required. The comparison operator to use. Accepted values: <ul><li><code>"=="</code>: Equal to</li><li><code>"!="</code>: Not equal to</li><li><code>">"</code>: Greater than</li><li><code>">="</code>: Greater than or equal to</li><li><code>"&lt;"</code>: Less than</li><li><code>"&lt;="</code>: Less than or equal to</li></ul> |
| `rightValue` | Any    | Required. The right operand for comparison                                                                                                                                                                                                                                                                                             |

## Return Value

The operation returns a boolean value (`true` or `false`) based on the result of the comparison.

### Comparison Logic

The `compare` operation uses logical rules to evaluate the relationship between the `leftValue` and `rightValue` properties, according to the selected `operator`. It examines the types and values of both operands and determines the appropriate comparison strategy.

If the operator is `==` or `!=`, the operation follows these rules:

1. If both values are `null`, they're considered equal and the operation returns `true`. If only one value is `null`, the operation returns `false`.
2. If either value is a boolean, both are coerced using language truthiness rules and compared as booleans. For example, the boolean `true` is equal to the string `"true"`.
3. If either value is a date or datetime value, both are parsed and compared as dates.
4. If either value is number-like, both are converted to numbers and compared numerically. For example, the string `"5.0"` is equal to the number `5`.
5. If either value is a string that can’t be converted to a number, the operation falls back to case-sensitive string comparison. For example, the string `"Hello"` isn’t equal to the string `"hello"`.

If the operator is `>`, `>=`, `<`, or `<=`, the operation follows these rules:

1. If either value is a number or is convertible to a number, the operation attempts to compare them numerically. For example, `{{compare "5.5" ">" 3}}` returns `true`.
2. If either value is a date or datetime value, both are parsed and compared as dates.
3. If either value is a string that can't be converted to a number or date, the operation performs an alphabetic, case-sensitive comparison. For example, `{{compare "apple" "<" "banana"}}` returns `true`.
