What are the potential security risks of using client-side scripting languages like JavaScript for dynamic content?

One potential security risk of using client-side scripting languages like JavaScript for dynamic content is the possibility of Cross-Site Scripting (XSS) attacks, where malicious code is injected into a webpage to steal sensitive information or perform unauthorized actions. To mitigate this risk, input validation and output encoding should be implemented to sanitize user input and prevent the execution of malicious scripts.

<?php
// Input validation to sanitize user input
$user_input = $_POST['user_input'];
$clean_input = htmlspecialchars($user_input);

// Output encoding to prevent XSS attacks
echo "<p>" . $clean_input . "</p>";
?>