---
title: "Condition elements"
slug: "condition-elements"
abstract: "Includes condition elements you can use in JavaScript when creating custom conditions."
---
# Condition elements

Before you start, make sure to familiarize yourself with the [types of parameters](https://doc.sitecore.com/cdp/en/users/sitecore-cdp/developer-center/conditions/create-a-custom-condition/types-of-parameters-for-conditions.html "Types of parameters for conditions") and [context parameters](https://doc.sitecore.com/cdp/en/users/sitecore-cdp/developer-center/conditions/create-a-custom-condition/context-parameters-for-conditions.html "Context parameters for conditions") for conditions, as well as [unsupported JavaScript functions](https://doc.sitecore.com/cdp/en/users/sitecore-cdp/developer-center/conditions/supported-and-unsupported-javascript-entities/unsupported-javascript-functions-and-alternatives.html "Unsupported JavaScript functions and alternatives"). Use the following structure to declare variables in conditions:

```text
let nameParam = `[[parametername | type | value1 | {config1: value1, config2: value2 } ]]`;

```

The following table contains descriptions of condition elements that you can use.

| Element | Description | Required |
| --- | --- | --- |
| `parameter_name` | The name of the field that the marketer sees when they add a condition. Example: Cart transaction. | Yes |
| `type` | The [type of input](https://doc.sitecore.com/cdp/en/users/sitecore-cdp/developer-center/conditions/create-a-custom-condition/types-of-parameters-for-conditions.html) that the marketer enters when using the condition. Options: string, text, number, enum. | Yes |
| `default_value` | The default value for the parameter input. | Optional, but necessary if you want to add variables that the marketer can select from. |
| `configuration` | A JSON configuration object that contains name/value pairs, in relation to the `type` you selected. | Optional |
| `placeholder` | A placeholder text that appears in the input box, helping marketers understand the type of input that is expected here. | Optional |

## Example 1: Condition to identify site visitors by type

This condition identifies site visitors by their type: whether new or returning. It does this by checking for an existing closed web session for the visitor. If the session exists, the visitor is classified as `"returning"`. If the session does not exist, the visitor is considered new. The `userType` parameter enables marketers to choose whether the visitor must be new or returning to pass the condition.

```javascript
(function () {
    var userType = "[[type | enum(new, returning) | | { required: true, placeholder: type }]]";
    var expectedType = "WEB";
    var expectedStatus = "CLOSED";
    var isReturning = false;

    if (guest && guest.sessions && guest.sessions.length > 0) {
         for (var index = 0; index < guest.sessions.length; index++) {
             if (
                 guest.sessions[index] &&
                 expectedType === guest.sessions[index].sessionType &&
                 expectedStatus === guest.sessions[index].status
             ) {
                 isReturning = true;
                 break;
             }
         }
     }

    if (isReturning && userType === "returning") {
         return true;
     } else if (!isReturning && userType === "new") {
         return true;
     } else {
         return false;
     }
})();

```

## Example 2: Condition to check a string value in a data extension

This condition checks for a specific value in a data extension using a string comparison. It loops through all data extensions associated with the visitor and looks for a matching field and value. The condition passes if the value in the specified field matches the one defined using the selected operator, such as `===` or `!==`.

```javascript
(function () {
    for (var i = 0; i < guest.dataExtensions.length; i++) {
        if (guest.dataExtensions[i].name === "[[ Data Extension Name | string]]"
        && guest.dataExtensions[i].values
        && guest.dataExtensions[i].values.[[Custom Field Name | string]]) {
            return guest.dataExtensions[i].values.[[Custom Field Name]] [[Operator | enum(===,!==)]] "[[ Value | string ]]";
        }
    }
    return false;
})();

```

## Example 3: Condition to check a numerical value in a data extension

This condition checks for a specific numeric value in a data extension. It works similarly to the string match version in the previous example but supports numeric comparison operators such as `===`, `!==`, `<`, `<=`, `>`, and `>=`.

```javascript
(function () {
    for (var i = 0; i < guest.dataExtensions.length; i++) {
        if (guest.dataExtensions[i].name === "[[ Data Extension Name | string]]"
        && guest.dataExtensions[i].values
        && guest.dataExtensions[i].values.[[Custom Field Name | string]]) {
            return guest.dataExtensions[i].values.[[Custom Field Name]] [[Operator | enum(===,!==,<,<=,>,>=)]] [[ Value | number ]];
        }
    }
    return false;
})();

```