How can JavaScript be used to pass a string to a textarea upon clicking a button?

To pass a string to a textarea upon clicking a button using JavaScript, you can create a function that retrieves the string value and sets it as the value of the textarea element. This can be achieved by targeting the textarea element using its id and updating its value property with the desired string. ```javascript function passStringToTextarea() { var stringToPass = "Hello, World!"; document.getElementById("myTextarea").value = stringToPass; } ``` In this code snippet, the function `passStringToTextarea` sets the value of the textarea element with the id "myTextarea" to the string "Hello, World!" when called. You can then call this function when the button is clicked to pass the string to the textarea.