What is JavaScript? Complete Introduction with Hello World! Example Part 1

What is JavaScript?

JavaScript is a very powerful client-side scripting language. JavaScript is primarily used to enhance user interaction with a webpage. In other words, you can make your webpage more lively and interactive with the help of JavaScript. JavaScript is also being widely used in game development and mobile application development.

Introduction to JavaScript

Javascript History

JavaScript was developed by Brendan Eich in 1995, which appeared in Netscape, a popular browser of that time.

Introduction to JavaScript

The language was initially called LiveScript and was later renamed JavaScript. There are many programmers who think that JavaScript and Java are the same. In fact, JavaScript and Java are very much unrelated. Java is a very complex programming language whereas JavaScript is only a scripting language. The syntax of JavaScript is mostly influenced by the programming language C.

How to Run JavaScript?

Being a scripting language, JavaScript cannot run on its own. In fact, the browser is responsible for running JavaScript code. When a user requests an HTML page with JavaScript in it, the script is sent to the browser and it is up to the browser to execute it. The main advantage of JavaScript is that all modern web browsers support JavaScript. Therefore, you do not have to worry about whether your site visitor uses Internet Explorer, Google Chrome, Firefox or any other browser. JavaScript will be supported. In addition, JavaScript runs on any operating system, including Windows, Linux, or Mac. Thus, JavaScript overcomes the main disadvantage of VBScript (now deprecated) which is limited to IE and Windows only.

Tools You Need

To begin with, you need a text editor to write your code and a browser to display the web pages you have developed. You can use any text editor of your choice that includes Notepad ++, Visual Studio Code, Sublem Text, Atom, or any other text editor you are comfortable with. You can use any web browser which includes Google Chrome, Firefox, Microsoft Edge, Internet Explorer etc.

A Simple JavaScript Program

You should place all your JavaScript code within the <script> tags (<script> and </script>), if you are keeping your JavaScript code in the HTML document itself. This helps your browser distinguish your JavaScript code from the rest of the code. Since there are other client-side scripting languages ​​(eg: VBScript), it is highly recommended that you specify the scripting language that you use. You have to use the type attribute in the <script> tag and set its value to text / JavaScript like this:

<script type="text/javascript">

Hello World Example:

This code is editable. Click Run to Execute
<html>
<head>
<title>My First JavaScript code!!!</title>
<script type="text/javascript">
alert("Hello World!");
</script>
</head>
 <body>
</body>
</html>

Note: type=”text/javascript” is not necessary in HTML5. Following code will work.

This code is editable. Click Run to Execute
<html> 
<head>
<title>My First JavaScript code!!!</title>
<script>
alert("Hello World!");
</script>
</head>
<body>
</body>
</html>

Summary

  • JavaScript is a client-side scripting language developed by Brendan Eich.
  • JavaScript can be run on any operating systems and almost all web browsers.
  • You need a text editor to write JavaScript code and a browser to display your web page.

3 Comments

Leave a Comment