Best JavaScript Tutorial Guide for Beginners

Posted by

Introduction

JavaScript is basically a programing language created by the company Netscape. The language has gained quite a lot of popularity in the recent months as it allows the web developers to modify the browser actions as well as the contents of the site in such a manner which is not at all possible using the traditional HTML tools or even CSS. Use of JavaScript on a web page empowers the developer to control the way his page reacts, and behaves to specific actions from the user, inspect the document elements displayed on the page, validate the form options before they are submitted, check the native browser details, set cookies for specific operations, add date and time to the page, and even embed simple mini games in the website. The complete language is simple to learn and understand once you have the basic knowledge of OOPS concepts and HTML.

Software and Knowledge Needed

Before starting up with the new language, you must have a basic understanding of HTML head and body areas, and few simple statements used to add images, insert hyperlinks, make paragraphs in the hypertext language. The software which you can use for starting the JavaScript tour is basic text editor. Windows OS users may go for Notepad or Notepad++ and Mac Users can use TextEdit or TextWrangler. The code would need a web browser (preferably Mozilla Firefox or Google Chrome) for successful compilation and running.

Getting Started

A Simple Program to print a custom message in JavaScript looks something like:

<html>

<head>

<title>JavaScript example</title>

<script language=”JavaScript”>

<!–

document.write(“My First JavaScript Program!”);

//–>

</script>

</head>

<body> Hello World! </body>

</html>

The use of “<!-“and “//->” in the above code ensures that the code is not displayed by older versions of browsers which lack JavaScript support. This ensures that the page does not malfunction on unsupported browsers.

Just like any other HTML file, you just need to copy paste the above code in your Notepad document, and then save it with an extension of “.html”. After the save is complete, simply right click on the file, and select option “Open With”. From here, choose a web browser (Mozilla Firefox if available). The code would execute on its own, and result would be displayed in the browser window.

Points to Remember

  • JavaScript codes are mostly placed in the “head” portion of the html but you may even use them under “body” area.
  • A JavaScript code normally starts with tag “<script language=”JavaScript”>” and ends with “</script>”.
  • A JavaScript will always be embedded into HTML code, and it can never stand alone.

Alert Message Box

If you want to add a custom alert message box to your site, then this can be established very easily using JavaScript. The code for adding a custom alert box is as follows.


<body>


<script>


window.alert("This is JavaScript Alert Box!")


</script>


</body>

Similarly you may add other alerts like:

  1. Confirm Action

Window. Confirm ("Are you sure you want to exit from this site?")

  1. Prompt Action

Window.prompt("User name field cannot be left blank.")

Leave a Reply

Your email address will not be published. Required fields are marked *