How .js file executed on the browser ?
How is .js is executed by the browser?
The browser’s built-in interpreter searches for <script> tag or .js file linked with HTML file while loading a web page, and then interpretation and execution starts.
Approach 1: Using plain <script> tag:
<script> js code</script>
Approach 2: Using <script src=””> with “src” Parameter:
To know more about file paths refer Path Name in File Directory.
Now, we will use the below code to link the ‘.js‘ file with the HTML file. For this task, we will use a <script src=” “> tag where will we provide the file path of our .js file in the src parameter. In this way when our HTML file starts getting loaded in the browser then the browser’s built-in interpreter searches for <script> tag or .js file linked with HTML file, and then interpretation and execution starts.