Organising your JavaScript

It's better to organise your JavaScript by splitting it out into separate files. This is quite easy. Create a new file called CartoonDinosaurs.js and type the following code into it:
document.write("Cartoon dinosaurs!");

Then create a new html document in the same directory with the following code inside it:
<html>
<head>
<script src="CartoonDinosaurs.js"></script>
</head>
<body>
</body>
</html>

Open this file in your browser. If you can see Cartoon dinosaurs! displayed on the page then all is well. Once you start writing a lot of JavaScript, organising everything into separate files helps you share code and keep everything tidy.

Comments

Popular Posts