Script Element
Element for executing JavaScript code
Script Element
The <script>
element executes JavaScript or Python code:
Prop | Type | Default |
---|---|---|
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
State Manipulation
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