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.
  • 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
  1. <html>  
  2. <body>  
  3.     <h1>  
  4.         My First JavaScript</h1>  
  5.     <p id="abhijeet">  
  6.         JavaScript can change the content of an HTML element.  
  7.     </p>  
  8.     <script>  
  9.         function myFunction() {  
  10.             x = document.getElementById("abhijeet"); // Find the element  
  11.             x.innerHTML = "Hello guyzz"// Change the content  
  12.         }  
  13.     </script>  
  14.     <button type="button" onclick="myFunction()">  
  15.         Click Me!</button>  
  16. </body>  
  17. </html> 
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
  1. <html>  
  2. <body>  
  3.     <h1>  
  4.         JavaScript</h1>  
  5.     <p>  
  6.         Please input a number.</p>  
  7.     <input id="abhijeet" type="text">  
  8.     <script>  
  9.         function myFunction() {  
  10.             var x = document.getElementById("abhijeet").value;  
  11.             if (x == "" || isNaN(x)) {  
  12.                 alert("Not Numeric");  
  13.             }  
  14.         }  
  15.     </script>  
  16.     <button type="button" onclick="myFunction()">  
  17.         Click Me!</button>  
  18. </body>  
  19. </html> 
Enter a number
input String value