HTML does not have any intellectual capabilities on its own: it can not perform arithmetic, check if someone has correctly completed a form, or make judgments based on how a web visitor interacts with it. Simply said, HTML allows users to view text, look at images, watch videos, and click links to visit additional web pages with more text, pictures, and videos. JavaScript is required in order to give your web pages intelligence so they may react to your visitors.
JavaScript is a programming language that allows a website to respond intelligently. You may use it to create informed online forms that notify users if they have forgotten to provide the required information. A web page’s elements can be made visible, hidden, or relocated around it. You can, for example, change the contents of a web page based on data retrieved from a server—without having to create a new web page. In other words, JavaScript allows you to make your websites more interesting, efficient, and useful.
Compiled Vs. Scripting Languages
JavaScript is also known as a scripting language. I have heard this phrase used for other languages like ColdFusion and PHP as well. What do you mean by scripting language?
The majority of the programs on your computer are written in the languages that are compiled. The act of writing code means nothing unless it can be translated into instructions that a computer can comprehend when compiled. Compiling is the process of turning a programmer’s code into a machine-readable form so that it may run on a computer.
Because a compiled program has been converted straight to instructions that a computer understands, it will run faster than one written in a scripting language once it is installed on your computer. Unfortunately, producing a program is a time-consuming process: You must first write the code, compile it, and then test it. If the program does not work, you have to start over from scratch.
On the other hand, a scripting language is simply compiled when an interpreter (another program that can turn the script into something a computer could understand) reads it. The JavaScript interpreter is built right into your web browser in this situation. When your browser comes to a web page with a JavaScript program on it, the browser converts the code into something the computer understands in order for you to view it.
As a result, every time the program is run, it must be translated for the computer, a scripting language runs more slowly than a compiled one. Web developers will love scripting languages: Because scripts are generally less complex and smaller than desktop applications, the speed isn’t as significant. In addition, program production and testing that use a scripting language are considerably faster because they don’t require compiling.
How To Write JavaScript?
To create JavaScript, you will need to have a web browser and either a text editor or an HTML editor.
You can now write JavaScript code once you have the software prepared. Create or open an HTML file with your text/HTML editor to add code of JavaScript to an HTML file. A docType element and some basic HTML tags, such as <html>, are included in a basic HTML file.
When you visit a website, you may occasionally notice some JavaScript code between the tags of the head and body. Alternatively, it may be found in the body (or even both) of the <body></body> tags. To isolate JavaScript code from HTML, it must be contained within a set of <script></script> tags.
The first line of the script contains one required attribute and one optional attribute. The type attribute is required, while src (which allows you to point to an external script file, covered later in this answer) is optional. The value of the type attribute was set to text/javascript.
You’ll paste your JavaScript code between the opening and closing script tags. You might, for example, place a straightforward string of text directly on the web page as a script.
One additional approach to include JavaScript on a page is to use an external text file instead. Make it a JavaScript file with the extension .js, then put it in your site’s root directory. The source of the opening script tag can be included in the page using the src attribute of the opening script tag.
You may then save the file with a .js extension. For example, you might name it write.js. You may now include it in your HTML source code via the src attribute of the opening script tag.
The code between the script tags has the same result as writing the code in JavaScript, but it won’t clog up the HTML code with JavaScript. Another benefit is that a single script may be used on many web pages, and modifying the script file only affects pages that use external script files. Script editing is useful since it may be done in one location rather than on each page with the script.
Where To Write And Execute JavaScript
- The simplest approach to get started with JavaScript is to write and execute it in the browser’s console. It’s useful for testing things out, but not an option for serious programming. In this video, we’ll look at why that is so.
- The second approach, which is to write JavaScript code in the index.html file (also known as inline script), however, has some drawbacks in terms of structuring and keeping HTML/CSS separate from your logic.
- The third and most frequent approach to writing JavaScript is to create a separate JavaScript file and connect it to the HTML file. This method is best as your application grows because it is tidy and efficient.
When you begin programming, you’ll be disappointed at how frequently your JavaScript programs don’t seem to function. The most typical reason for nonfunctioning code for new developers is simple spelling mistakes. Always double-check that you’ve entered commands (such as alert in the first script) correctly.
Make sure you include both opening and closing punctuation marks, as well as any required single-quote or opening/closing parentheses, when necessary. Also, note that punctuation is commonly paired.

Brian Taylor is a JavaScript developer and educator, dedicated to demystifying programming for newcomers. With a career spanning over a decade in web development, Brian has a deep understanding of JavaScript and its ecosystem. He is passionate about teaching and has helped countless beginners grasp the fundamentals of JavaScript, enabling them to build their own web applications.



