AIML Docs

Script Element

Element for executing JavaScript code

Script Element

The <script> element executes JavaScript or Python code:

<script>
// JavaScript code here
console.log("Executing script...");
</script>
PropTypeDefault
language?
"javascript" | "python"
javascript

Of note, each script element is executed in a new context, so you don't need to worry about variable collisions. This also means that you can't define functions that are used by multiple script elements.

Examples

Inline Script

<script>
// Perform calculations
const result = calculateTotal(items);
console.log(`Total: ${result}`);
</script>

State Manipulation

<script>
// Update state based on calculations
const newValue = performComplexCalculation();
dataModel.setValue("state.result", newValue);
</script>

Usage Notes

  • Use scripts for complex logic that's difficult to express with other elements
  • Keep scripts focused and modular
  • Consider moving complex logic to external files
  • Be cautious with global state modifications
  • Use appropriate error handling

On this page