<html>
<script type="text/javascript">
alert(2);
</script>
</html>
<html>
<head>
<script type="text/javascript"> alert("Mã js này được đặt trong thẻ HEAD");</script>
</head>
<body>
<script type="text/javascript">
document.write("Mã js này được đặt trong thẻ BODY");
</script> </body>
</html>
<html>
<head>
<script type="text/javascript" src="abs.js" > </script>
</head>
<body>
Mã Js được đặt trong file abs.js </body>
</html>
<html>
<body>
<div style='border: 1px solid red;' onclick="alert(2);">
Click chuột ở đây để thực thi mã JS
</div>
</body>
</html>
<html>
<body>
<a href='javascript: alert(document.body.innerHTML);'>
Click chuột ở đây để thực thi mã JS
</a>
</body>
</html>
<html>
<head>
<style type="text/css">
.JSCode {
border: 1px solid red;
height: expression(200 + 'px');
}
</style>
</head>
<body>
<div class='JSCode'>
Dòng mã JS:
height: expression(200 + 'px')
Đã ấn định chiều cao của phần tử này là 200px;
</div>
</body>
</html>
alert(2);
<html>
<script type="text/javascript" src="abs.js"></script>
</html>
Cuối cùng có một số qui ước như sau: tài liệu HTML sẽ thường được gọi (viết) là file html, tài liệu Javascript gọi là file js.