Structure of JavaScript

Structure of JavaScript thumbnail
The JavaScript scripting language.

JavaScript is a dynamic scripting language that is used to add interactivity to static HTML pages by embedding blocks of code on any part of the web page. Usually, JavaScript is implemented on the client side, that is the browser, to provide enhanced and dynamic interaction with web pages. This is the most significant application and implementation of JavaScript.

  1. The Primer

    • All JavaScript code should begin with the tag "<script language= "type/javascript">. Adding this line allows for JavaScript to be validated and thus less errors. In cases in which the browser does not support JavaScript the following lines are added to hide the code:

      <script language= "type/javascript">
      <!---
      document.write ("JavaScript platform initiated!")
      //- - >

      </script>

      The above code can be inserted anywhere on a HTML code window to display the text "JavaScript platform initiated!" if the browser supports JavaScript.

    Variables

    • These are containers that are used to hold data and that can be referenced anywhere on the code. Variables thus allow for data reuse, simplifying the programming process. Variables can be created and initiated at the same time as shown below:

      var MyName = "David";

      The above variable is called "MyName" and holds the value "David." I can now refer to that variable anywhere on the code by simply calling "MyName."

    Loops

    • Looping in JavaScript is implemented when you do not want code to follow a straight, linear fashion. This is one of the flow control techniques that allows for certain blocks of code to be run when certain conditions are met. Loops can be implemented using either a single command or multiple commands. Loops form an important structure of any JavaScript that has repeating script blocks. Loops can either be "for" loops, "while" loops or "dowhile" loops.

    Forms

    • After creating forms in your average text editor, you can access and manipulate the text field contents of the forms using JavaScript. The contents of these fields can be displayed in a dialog box as a pop up using JavaScript. Form fields can also be updated dynamically using JavaScript by use of what is called an "OnClick" event handler that specifies the JavaScript code that executes when the user clicks on a link on the form. Form structures thus form an important element that allows for client-side updating of form fields.

    Functions

    • These are blocks of code that contain statements executed when a certain event or call is made to the function. These blocks of code are thus not executed when, say, a page loads. They require the user to trigger their execution. They thus form an important code structure within a page.

Related Searches:

References

Resources

  • Photo Credit laptop image by Angie Lingnau from Fotolia.com

Comments

You May Also Like

  • History of Javascript

    Javascript was developed in 1996 and appeared as a server side language that accompanied the Netscape Internet browser. The basic idea behind...

  • PHP Javascript Tutorial

    Open Notepad and create the structure of a basic Web page: <html> <head> <title> </title> </head> <body> </body> </html> Most pages on...

  • Javascript DOM Tutorial

    Understanding the DOM is key to using JavaScript effectively. The elements of a web page that are available to JavaScript functions exist...

  • What Is the Meaning of Scripting Language?

    Computers understand information as represented by series of binary digits (1's and 0's). Accordingly, programming languages usually fall into or between two...

  • The Differences between Java and JavaScript

    The Differences between Java and JavaScript. Java and JavaScript are both object-oriented languages. Aside from this fact and their similar names, few...

  • Replacing JavaScript

    If you need to replace the JavaScript on a website, there are a number of places you may need to look. Websites...

  • How to Sort Links Alphabetically in JavaScript

    JavaScript is a client-side scripting language that contains many of the features that are typically available in full-featured programming languages, including logic...

  • Difference Between Javascript & Java Applets

    Perhaps due to their somewhat similar names, there is a lot of confusion among Internet users (and even some industry insiders) about...

Related Ads

Featured