What is JavaScript? Complete Introduction with Hello World! Example
You will learn all the basics of JavaScript in this guide. JavaScript is used to create dynamic client-side pages.
What is JavaScript?
JavaScript is an interpreted, client-side, event-based, and object-oriented scripting language that you can use to add dynamic interactivity to your web pages.JavaScript scripts are written in plain text, such as HTML, XML, Java, PHP, and almost any other modern computer code. In this tutorial, we will use Windows Notepad to create and edit our JavaScript code, but there are a large number of alternatives available. NotePad is chosen to demonstrate the immediacy and simplicity of JavaScript.
JavaScript is not Java, although if you come from Java, you will notice that both languages look similar when written. Java is a complete and comprehensive programming language similar to C or C ++, and although JavaScript can interact with Java web applications, the two should not be confused.
Different web browsers will execute your JavaScript in different, sometimes incompatible ways. To avoid this, it is often necessary to use JavaScript itself to detect the capabilities of the browser you are in and modify its operation based on the result.
There are the following JavaScript features:
You must put all your JavaScript code inside the <script> tags (<script> and </script>) if you keep your JavaScript code inside the HTML document itself. This helps your browser distinguish your JavaScript code from the rest of the code. As there are other client-side scripting languages (Example: VBScript), it is strongly recommended that you specify the scripting language that you use. You have to use the type attribute inside the <script> tag and set its value to text / javascript like this:
<script type = "text / javascript">
JavaScript features
There are the following JavaScript features:
- All popular web browsers support JavaScript as they provide built-in runtime.
- JavaScript follows the syntax and structure of the C programming language. Therefore, it is a structured programming language.
- JavaScript is a weakly typed language, where certain types are emitted implicitly (depending on the operation).
- JavaScript is an object-oriented programming language that uses prototypes rather than classes for inheritance.
- It is a light and interpreted language.
- It is a case-sensitive language.
- JavaScript is compatible with various operating systems, including Windows, macOS, etc.
- Provides good control to users over web browsers.
A simple JavaScript program
You must put all your JavaScript code inside the <script> tags (<script> and </script>) if you keep your JavaScript code inside the HTML document itself. This helps your browser distinguish your JavaScript code from the rest of the code. As there are other client-side scripting languages (Example: VBScript), it is strongly recommended that you specify the scripting language that you use. You have to use the type attribute inside the <script> tag and set its value to text / javascript like this:
<script type = "text / javascript">
Hello World Example:
See the Pen Simple Javascript Program by Amit Kumar (@amit0341) on CodePen.
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.
- JavaScript used to add dynamic interactivity to your web pages.
- JavaScript is an interpreted, client-side, event-based, and object-oriented scripting language