- Previous
- Next
JavaScript is a browser-based scripting language. It means you can control certain things on a browser like validating user input, throw an alert and so on. These are some common examples, JavaScript can do much more than this.
A web developer must know how to write JavaScript programs because these are basic skills expected of him or her. The good news is anyone can learn JavaScript and it’s not difficult either. To help you get started, you will find a simple JavaScript program and its output below.
First JavaScript Program
A lot of people get confused between Java and JavaScript – both are not same. JavaScript can only be used on a web page, but the scope of Java programming is much more than a web document.
To start writing your script, all you need is a text editor. You can use the windows notepad or get a professional notepad like Notepad++, Sublime Text, etc. They all come with more features than a regular windows notepad program.
Let’s get started …
<!DOCTYPE html>
<html>
<head>
<title>First JavaScript</title>
<script type="text/JavaScript">
document.write("First JavaScript program !");
</script>
</head>
<body>
</body>
</html>
This script prints some text on a browser window – “First JavaScript program !” and it is written in <script> … </script>
tags and the document.write()
is an instruction to the browser to write the text as an output.The <script>
tag tells the browser about the kind of script you are using which is type="text/JavaScript"
and the whole script is embedded inside HTML document or web page.
The tags <html> … </html>
shows the start and end of HTML document. So, you can write complex scripts within <script> … </script>
tags and the browser executes it for you.
Output to Browser
The output of the program is a single sentence only. We will see more examples of output from a JavaScript program in future articles.