<script> Element

  • Used to define JavaScript within the document
  • Can contain script statements, or
  • Can refer to an external script file via the src attribute

 

<!DOCTYPE html>
<html>
	<head>
		<title>My Document Title</title>
		<script>
			document.write("Hello, World!");
		</script>
		<script src="/js/myJavaScript.js"></script>
	</head>
	<body>

	</body>
</html>

Save & refresh browser:

Hello, World!

 

*note: if defining an external src file the script element must be empty.

Leave a Reply