What are the advantages of separating JavaScript code into external files rather than embedding it within PHP files?
Separating JavaScript code into external files rather than embedding it within PHP files helps in better organization and maintenance of code. It also allows for better reusability of code across multiple pages and makes it easier to collaborate with other developers. Additionally, external JavaScript files can be cached by the browser, leading to faster loading times for subsequent visits to the website.
<!DOCTYPE html>
<html>
<head>
<title>External JavaScript Example</title>
<script src="external.js"></script>
</head>
<body>
<h1>External JavaScript Example</h1>
<button onclick="sayHello()">Click me</button>
</body>
</html>