Introduction to JavaScript: Day 1


In this article, you learn basic concepts of JavaScript and the purpose of JavaScript used in Web Applications. It gives an initial push to start you with JavaScript. Topics covered in this article as follows:
  • What is JavaScript?
  • JavaScript syntax and example.
  • What can a JavaScript do?

What is JavaScript?

JavaScript is a scripting language for use within HTML Web pages. It Was designed to add interactivity to HTML pages, it is a scripting language is a lightweight programming language. JavaScript code is usually embedded directly into HTML pages. JavaScript is an interpreted language (means that scripts execute without preliminary compilation).

JavaScript syntax and example

A JavaScript statements are placed within the <script>... </script> HTML tags in a web page. Here are some tips to remember when writing JavaScript commands.
  • JavaScript code is case sensitive
  • JavaScript statements end with a semi- colon (;)
  • White space between words and tabs are ignored
  • Line breaks are ignored except within a statement
Use the <script> tag (also use the type attribute to define the Scripting language), you can add this tag in </head> as well as </body> tag also like following: 
  1. <!DOCTYPE html>      
  2. <html >      
  3. <head>      
  4. <title></title>      
  5. <script type="text/javascript">      
  6.  //place your code here    
  7. </script>      
  8. </head>      
  9. <body>      
  10. <script type="text/javascript">      
  11. //place your code here    
  12.  </script>    
  13.  </body>      
  14. </html>   
The script tag takes two important attributes:
  1.   Language: This attribute specifies what scripting language you are using. Typically, its value will be JavaScript. 
  2.   Type: This attribute is what is now recommended to indicate the scripting language in use and its value should be set to "text/javascript".
JavaScript segment look like this:
  1. <!DOCTYPE html>      
  2. <html >      
  3. <head>      
  4. <title></title>      
  5. </head>      
  6. <body>      
  7. <script language="javascript" type="text/javascript">      
  8.         document.write("Hello from C# Corner");      
  9.  </script>   
  10.     </body>    
  11. </html>     
    Output:  Hello from C# Corner

    What can a JavaScript do?

    • JavaScript gives HTML designers a programming tool
    • JavaScript can put dynamic text into an HTML page
    • JavaScript can react to events
    • JavaScript can read and write HTML elements
    • JavaScript can be used to validate input data
    • JavaScript can be used to detect the visitor's browser
    • JavaScript can be used to create cookies


    I hope this article is useful for JavaScript beginners, if you have any suggestion then please contact me.