You don't need to do anything special when using the text type in JavaScript, as it is similar to the String type in JavaScript.
<? register input @TextProperty ?>
<input type="hidden" id="<?attr OutputId(@TextProperty) ?>" name="<?attr OutputId(@TextProperty) ?>">
<? startupscript ?>
// It is important to use 'js' encoding when outputting the property value in JavaScript blocks.
let value = <?js @TextProperty ?>;
value = value.toUpperCase();
console.log("Result in uppercase:", value);
<? end ?>
<? submitscript ?>
const el = document.getElementById(<?js OutputId(@TextProperty) ?>);
// Performing a postback with the text property is straightforward.
el.value = "Hi, can you post me back please? ♡";
<? end ?>
Print Output Overview
Depending on the encoding format, different outputs are generated. Let's assume a variable var @s: text holds the value ">>> Stan Laurel & Oliver Hardy <<<". The following outputs will be generated:
Encoding
Output
<?= @s ?>
>>> Stan Laurel & Oliver Hardy <<<