Introduction
In this article you learn basic concepts of JavaScript and 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:
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:
- Language: This attribute specifies what scripting language you are using. Typically, its value will be JavaScript.
- 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:
- <!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 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
Summary
I hope this article is useful for JavaScript beginners, if you have any suggestion then please contact me.