JavaScript files
Last updated
Last updated
© 2024 UI Bakery
JavaScript files help organize custom functions and variables. They're perfect for storing reusable helpers and utilities within components and actions.
To create a JS file, click the plus button in the Actions panel and select the JS file option:
All top-level variables and functions defined in a JS file are accessible in components and actions.
JavaScript files are scoped based on their creation context. App-level JS files can be utilized across any component or action within the app, while page-level files are restricted to their specific page.
When multiple functions with the same name are defined in a scope, the most recent definition will take precedence.
Functions and variables defined in one file can be used in another. Note that since JS files are added to a page as scripts, you can only reference definitions from files loaded earlier.
Custom libraries in the custom code section, along with default libraries like moment
and lodash
, are available in the JS files:
To troubleshoot an issue, insert a console log statement and run the function within an action or component. The logs will appear in the logs panel, prefixed with the file name where the code resides.
Code that contains invalid JavaScript and cannot be parsed is not incorporated into the page.