Skip to main content
Sitecore Documentation
  • Learn
  • Downloads
  • Changelog
  • Roadmap
PersonalizeCloud Portal
Sitecore Personalize
        • Add a programmable decision
        • Create a programmable with the Code Assistant
        • Add a decision template
        • Examples of programmable decisions
            • Supported JavaScript functions
            • Unsupported JavaScript functions and alternatives
        • Use custom fields
        • Including dates
        • Copy programmable decisions
        • Including print statements
        • Troubleshooting
    • Managing data systems
  • Using client-side JavaScript
  • Glossary
  1. Supported and unsupported JavaScript entities
  1. Sitecore Personalize
  2. Introduction to decisioning in Sitecore Personalize
  3. Managing programmable decisions
  4. Supported and unsupported JavaScript entities
  5. Supported JavaScript functions

Supported JavaScript functions

The following are supported JavaScript functions with code examples. You can use these when writing server-side JavaScript for a programmable decision.

Array destructuring

Sitecore Personalize supports the array destructuring feature. You can use the following JavaScript to unpack values from an array:

var [a, ...b] = [1, 2, 3];
print(a); // 1
print(b); // [2, 3]

Array filter/map/reduce

Sitecore Personalize supports the .map(), .reduce(), and .filter() methods.

The filter() method applies a conditional statement against each element in an array. If the condition returns true, the element is pushed to the output array.

The map() method creates a new array from an existing array and applies a function to each one of the elements of the first array.

The reduce() method runs a reducer function on each element of the array to reduce the array of values to just one.

The following JavaScript includes examples:

const getMax = ( max, cur ) => Math.max( max, cur );

print(
    [ { x: 10 }, { x: 66 }, { x: 150 } ]
    .filter(el => el.x < 100)
    .map( el => el.x )
    .reduce( getMax, -Infinity )
);
// expected output: 66

Arrow functions

Sitecore Personalize supports the arrow function that lets you write a shorter function syntax. If the function has only one statement, and the statement returns a value, you can remove the brackets and the return keyword.

The following JavaScript includes an example:

let materials = [
  'Hydrogen',
  'Helium'
];
print(materials.map(material => material.length));
// expected output: Array [8, 6]

Classes

Sitecore Personalize supports class as a type of function. Instead of using the keyword function to initiate it, use the keyword class. The properties are assigned inside a constructor() method.

The following JavaScript includes an example:

let Rectangle = class {
  constructor(height, width) {
    this.height = height;
    this.width = width;
  }
};
print(Rectangle.name);
// output: ""Rectangle""

Default function parameters

Sitecore Personalize supports default function parameters. The default parameter enables you to set default values for function parameters if a value is not passed in.

The following JavaScript includes an example:

function multiply(a, b = 2) {
  return a * b;
}
print(multiply(5));
// expected output: 10

Let and const bindings

Sitecore Personalize supports let bindings and const bindings.

Let bindings are created at the top of the (block) scope containing the declaration.let variables and are not initialized until their definition is evaluated.

The const statement declares a local variable the same as the let statement. However, after it is initialized, it cannot be reassigned with any other value. It must be initialized when declared.

The following JavaScript includes examples:

const foo = 'bar';
let ten = 10;
print(foo, ten);
// expected output: bar, 10

Object destructuring

Sitecore Personalize supports object destructuring. Use this to extract properties from objects and bind them to variables.

The following JavaScript includes an example:

var o = {p: 42, q: true};
var {p, q} = o;
print(p); // 42
print(q); // true

Rest parameters

Sitecore Personalize supports the rest parameter as an improved way to handle various input as parameters in a function. The rest parameter syntax enables you to represent an indefinite number of arguments as an array.

The following JavaScript includes an example:

function sum(...theArgs) {
  return theArgs.reduce((previous, current) => {
    return previous + current;
  });
}
print(sum(1, 2, 3));
// expected output: 6

Spread syntax

Sitecore Personalize supports the spread syntax (...), which allows an iterable to expand in places where zero or more arguments are expected.

The following JavaScript includes an example:

function sum(x, y, z) {
  return x + y + z;
}
const numbers = [1, 2, 3];
print(sum(...numbers));
// expected output: 6

Template literals

Sitecore Personalize supports the template literal syntax, which enables you to use backticks (`) instead of single (') or double (") quotes when working with strings.

The following JavaScript includes an example:

const a = 5;
const b = 10;
print(`Fifteen is ${a + b} and not ${2 * a + b}.`);
// ""Fifteen is 15 and not 20.""
If you have suggestions for improving this article, let us know!

© Copyright 2026, Sitecore A/S or a Sitecore affiliated company.
All rights reserved.

Privacy policySitecore Trust CenterTerms of use