Since JavaScript commands run on the browser, we need to add JavaScript codes to our web page.

There are various methods of adding JavaScript code to a web page.

JavaScript codes can be written between the <script> and </script> tags.


It can be written to HTML properties such as onclick, which indicates when the HTML element is clicked, onmouseover, which indicates that the HTML element is hovered.

<button onclick="alert('')">Click</button>

After the JavaScript codes are written to the external .js file, the <script> tag can be written to the src property by specifying the file name.

JavaScript codes (example.js)


HTML Codes

<script src="example.js"></script>

Codes are written to the external JavaScript file without the <script> and </script> tags.

Written JavaScript codes can be inserted into <head> or <body> tags.

<!DOCTYPE html>
<html lang="en">

  <meta charset="UTF-8">
  <title>Baransel Arslan</title>



Long JavaScript commands can slow down the page load.

If the codes in the page or in external JavaScript files are added to the end of the <body> tag, the page will open faster.