Skip to main content

Overview

Equality operators compare values for equality or inequality. Rule Engine JS provides two equality comparison operators:

eq

Tests if two values are equal

neq

Tests if two values are not equal

Architecture

Equality operators are implemented in the ComparisonOperators class which extends BaseOperator: Source Files:
  • Equality operators: src/operators/comparison.js
  • Base operator: src/operators/base/BaseOperator.js
  • Type utilities: src/utils/TypeUtils.js
  • Unit tests: tests/unit/operators/comparison.test.js

Key Features

  • Dynamic field comparison - Compare two fields or a field to a literal value
  • Strict/loose modes - Control type coercion behavior (== vs ===)
  • Type-safe equality - Handles primitives, objects, arrays, null, undefined
  • Comprehensive validation - Validates argument count and types

eq - Equals

Tests if two values are equal.

Syntax

Parameters

string | any
required
Left operand - field path or literal value
string | any
required
Right operand - field path or literal value
object
Configuration options

Returns

boolean - true if values are equal, false otherwise

Examples

Common Use Cases

Type Coercion: By default, eq uses loose equality (==). Use { strict: true } or create a strict engine for type-safe comparisons.

neq - Not Equal

Tests if two values are not equal (inverse of eq).

Syntax

Parameters

string | any
required
Left operand - field path or literal value
string | any
required
Right operand - field path or literal value
object
Configuration options

Returns

boolean - true if values are not equal, false otherwise

Examples

Common Use Cases

For checking if a value is NOT in a list, prefer the notIn operator instead of multiple neq conditions.

Error Handling

Common Errors

Error Recovery

Type Coercion

Equality operators support both strict and loose comparison modes:

Setting Strict Mode

Use strict mode in production to prevent unexpected type coercion bugs.

Numeric Operators

GT, GTE, LT, LTE

Special Operators

isNull, isNotNull, between

Array Operators

in, notIn

Logical Operators

and, or, not

State Operators

changed, changedTo, changedFrom

All Operators

Complete operator reference

API Reference

For complete API documentation: