How to Improve Your Code with Smart JavaScript Techniques and Patterns

How to Improve Your Code with Smart JavaScript Techniques and Patterns

Among all the programming languages that we use today, Java is the most advanced as well as extensively used language. Today there is no organization or business enterprise that does not make use of Java. This is the reason why there is huge demand for this particular programming language in the market. However, Java Script is of great importance for improving our programming experience. There are few exclusive techniques in Java Script that can instantly improve the usability of all web pages.

Basically, we use Java Script within Java for the development of dynamic web pages. In fact, one of the main reasons why developers should use Java Script is for improving the user’s experience while working on the internet. Following in this article there are some of the easiest JavaScript techniques & patterns, you can improve your web design experience using these techniques.


JQuery Hover Sub Tag Cloud

This piece of code will add a nice touch to the tag clouds present on your web page. By hovering the cursor over any tag, the sub tags within that tag will be shown within a pop- up box. It is very simple to add the JQuery Hover Sub Tag Cloud effect and it looks decent as well.


Image Upload and Auto- Crop

Using the Image Upload and Auto- Crop technique, we can crop any picture after uploading it and hence it can be extensively used by all web applications. Sadly, this tool is used very rarely. There are thousands of web applications on the internet which can benefit from this Java Script technique. Cropping is the most basic function associated with a picture and to be able to do that after uploading the picture will come handy in many situations.


Opacity Change

Using Opacity Change Java Script, we can bring change to the opacity of an element. There are certain situations under which this technique can be used more often. These include showing any content after clicking on it, to show hovered content and many others.


Password Strength Meter

Since system attackers and hackers are becoming smarter with each passing day, there is a need for creating stronger and reliable passwords in order to protect our confidentiality. Often, users do not go through the details properly and hence land up in trouble. Using this Password Strength Meter Java Script code, we can determine the strength of our password. A coloured meter will show the strength in real time. From the perspective of safety, this technique should be used by each and every web application.


jQuery Auto tab

While entering security pins as well as passwords, there is often the need for entering only a specific number of characters in a field. The JQuery Auto tab automatically tabs the input to the next field. Very convenient to use, this Java Script technique should be a part of every form where there is the need to input data into multiple fields.


Magic Zoom

You must have seen and used this technique on all the eCommerce websites. Using this technique, there is no longer the need to click on any image for zooming it. All we need to do is hover cursor on the picture and it will automatically get magnified. It is similar to looking through a magnifying lens. Unlike other techniques, Magic Zoom is not free and we have to splurge some money for using it and its trial version is also available.


Generating HTML Markup

following code helps you to create HTML markup dynamically –

var values = ['one', 'two', 'three', 'four', 'five'];

var html = '';
for (var i = 0; i < values.length; i++) {
  html += ''+ values[i] +'';

This can be rewritten without using for loop –

var html =, i) {
  return ''+ text +': '+ i +''


Text Manipulation

Consider the following JavaScript code –

var str = 'the sky is blue. apples are green.';

var para = str.split('.'), // get array of paragraphs
    i = 0, len = para.length, p;

for (; i < len; i++) {
  p = para[i].trim(); // make sure there's no additional whitespace
  para[i] = p.substr(0,1).toUpperCase() + p.substr(1, p.length);

para = para.join('. ').trim(); // put everything back together

//^ "The sky is blue. Apples are green."

Now this can be done using regular expression in the shorter and smarter way –

str = str.replace(/([^.]+\.\s?)/g, function(_, para) {
  return para.replace(/^\w/, function(first) {
    return first.toUpperCase();

// ^ "The sky is blue. Apples are green."

Written by Amit Tripathi

Being an professional blogger, Amit has work on many professional blogs for same niche. Get Amit on Google+



Amazing Photoshop Brushes to work on Grunge Designs

50 Fantastic Examples of Underwater Photography