Introduction to JavaScript

JavaScript was invented by Brendan Eich.

JavaScript made its first appearance in Netscape 2.0 in 1995 with the name LiveScript.

ECMAScript is the name of the standard Javascript and "Standard ECMA-262 ECMAScript Language Specification" is the official name of the JavaScript standard.

JavaScript is most commonly used as a client-side scripting language. This means that JavaScript code is written into an HTML page. 

Although the names are much alike, JavaScript is primarily a scripting language for use within HTML pages, whereas Java is a real programming language that does quite different things from JavaScript.

Features

  • JavaScript is a lightweight, interpreted programming language.
  • Designed for creating network-centric applications.
  • Open and cross-platform.

Advantages of JavaScript

  • Less server interaction
  • Immediate feedback to the visitors
  • Increased interactivity
  • Richer interfaces

The contents of  HTML elements are commonly manipulated using JavaScript.

Example 1: Changing HTML Content

<html>

<body>

    <h1>

        My First JavaScript</h1>

    <p id="abhijeet">

        JavaScript can change the content of an HTML element.

    </p>

    <script>

        function myFunction() {

            x = document.getElementById("abhijeet"); // Find the element

            x.innerHTML = "Hello guyzz"; // Change the content

        }

    </script>

    <button type="button" onclick="myFunction()">

        Click Me!</button>

</body>

</html>

Output

Changing HTML Content

HTML Content

The isNaN() function determines whether a value is an illegal number (Not-a-  Number).

So we can say that  the isNaN() function returns true if the value is  NaN (Not-a-Number) and false if not.
 
Example 2: Validate Input

<html>

<body>

    <h1>

        JavaScript</h1>

    <p>

        Please input a number.</p>

    <input id="abhijeet" type="text">

    <script>

        function myFunction() {

            var x = document.getElementById("abhijeet").value;

            if (x == "" || isNaN(x)) {

                alert("Not Numeric");

            }

        }

    </script>

    <button type="button" onclick="myFunction()">

        Click Me!</button>

</body>

</html>

Output 

Enter a number 
input String value 
Output 

Up Next
    Ebook Download
    View all
    Learn
    View all