Quick JavaScript Tips and Practices


Web Design India
Java Script, one the most popular web programming languages, has expanded its significance not only among the general web authors and amateurs but even among the professional programmers because of the ease and efficiency it offers in the programming format. Inspite of it being the best programming language for web designing, not many know the salient features offered by it, apart from its common features.  Some of the interesting tips, recommendations, and best practices for JavaScript coding are listed below, that would help you to use Java Script in new and refined form.

1. Defer Attribute

Using Defer Attribute gives extra time to the externally linked scripts to load, until the page completely loads. This is especially advantageous in case of Internet Explorer browser, the only one that currently supports a Defer. To add defer to the coding of the webpage, all you need to do is add defer=”defer” in your <script> tag and that will quickly take care of that problem.

Visual Example

<script type=”text/javascript” defer=”defer”></script>

2. C Data Section to avoid Validation Errors

If you are faced with regular Validation Errors in the designing format of your webpage, then this simple tip will be a savior for you. Merely use C Data Section to end your coding; this will significantly decrease the validation errors you generally face.

Visual Example

<div>

<p>

<script type=”text/javascript”>

//<![CDATA[

var my_variable = 100;

if (my_variable < 50) {

// do something here...

}

//]]>

</script>

</p>

</div>

3. Avoiding Java Key words

There are several words that are reserved as Keywords by Java Script, that hamper the programming, designing, loading and processing of the webpage. By avoiding the Java Keywords in your script, and using other custom identifiers in their place, you can ensure smooth operation of any Java coded Webpage.

Some of the common Java Script Keywords are listed below

  • Break
  • Case
  • Catch
  • Continue
  • Default
  • Delete
  • Do
  • Else
  • Finally
  • For
  • Function
  • If
  • In
  • Instanceof
  • New
  • Return
  • Switch
  • This
  • Throw
  • Try
  • Typeof
  • Var
  • Void
  • While
  • With

4. Localized use of Variables

In any coding language, where multiple options are to be used on the same webpage, there is always a chance that the variable might be used by other codes for which it is not designed. This can be easily avoided, by localizing the use of variables for a particular operation or the function it has to perform. By localizing variables, you ensure that they are abolished as soon as the function is executed and cannot be used later by other codes.

5. Case Sensitive Custom Identifiers

All the custom identifiers used in Java Script Coding, are case sensitive and using different case for the same identifier in the code can create errors and operations glitches in the functioning of the webpage. So by avowing use of dual case in the code, you not only use formal and globally accepted form of identifiers but also ensure that you don’t accidentally declare two different variables when you actually meant to create just one.

Visual Example

var myVariable = “data”;
var myvariable = “more data”;

These are only few of the tips and practices that will make your work on JavaScript easier. You can explore many more of them.

About these ads

Posted on July 8, 2010, in JavaScript Tips and tagged , . Bookmark the permalink. 1 Comment.

  1. web designing bangalore

    Nice tips and really helpful, thanks for sharing…

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 136 other followers

%d bloggers like this: