Introduction to JavaScript: Day 1

Introduction

In this article, you learn the 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 are as follows,

  • What is JavaScript?
  • JavaScript syntax and example
  • What can 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 and lightweight programming language. JavaScript is an interpreted language (which means that scripts execute without preliminary compilation). JavaScript code is usually embedded directly into HTML pages.

JavaScript syntax and example

JavaScript statements are placed within a web page's <script>... </script> HTML tags. 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 is 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 the following,

Syntax

<!DOCTYPE html>      
<html >      
<head>      
<title></title>      
<script type="text/javascript">      
 //place your code here    
</script>      
</head>      
<body>      
<script type="text/javascript">      
//place your code here    
 </script>    
 </body>      
</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 recommended to indicate the scripting language in use, and its value should be set to "text/javascript".

The JavaScript segment looks like this,

<!DOCTYPE html>      
<html >      
<head>      
<title></title>      
</head>      
<body>      
<script language="javascript" type="text/javascript">      
        document.write("Hello from C# Corner");      
 </script>   
    </body>    
</html>     

Output

Hello from C# Corner

What can 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

Summary

I hope this article is helpful for JavaScript beginners; if you have any suggestions, then please get in touch with me.

Reference

  1. Programming Basics in JavaScript: Day 2
  2. Comments and Objects in JavaScript: Day 3
  3. Scope and Events in JavaScript: Day 4
  4. Array in JavaScript: Day 5
  5. Page Re-direction in JavaScript: Day 6
  6. Errors and Exception Handling in JavaScript: Day 7
  7. Debugging in JavaScript: Day 8
  8. Hosting in JavaScript: Day 9