Here is the Best  JavaScript Tips and Tricks For you.

We know that JavaScript is most Important programming language in the world. JavaScript is most commonly used in the web, mobile hybrid apps, server side programming and many other applications. It’s a challenge for many new developers to display different  functions in JavaScript. E.g

  • Array of Country Names
  • Auto Select Textarea Text
  • Basic Alert
  • Comments in JavaScript
  • Format Currency
  • JavaScript Date
  • JavaScript Datatypes
  • JavaScript Libraries

In this article we will share different JavaScript tips and tricks for new developers.


You May Also Like:

Array of Country Names

Here We will give you the code for insert an array of country names. You just enter this code

var country_list = ['Afghanistan', 'Åland Islands', 'Albania', 'Algeria', 'American Samoa', 'Andorra', 'Angola', 'Anguilla', 'Antigua and Barbuda', 'Argentina', 'Armenia', 'Aruba', 'Australia', 'Austria', 'Azerbaijan', 'Bangladesh', 'Barbados', 'Bahamas', 'Bahrain', 'Belarus', 'Belgium', 'Belize', 'Benin', 'Bermuda', 'Bhutan', 'Bolivia', 'Bosnia and Herzegovina', 'Botswana', 'Brazil', 'British Indian Ocean Territory', 'British Virgin Islands', 'Brunei Darussalam', 'Bulgaria', 'Burkina Faso', 'Burma', 'Burundi', 'Cambodia', 'Cameroon', 'Canada', 'Cape Verde', 'Cayman Islands', 'Central African Republic', 'Chad', 'Chile', 'China', 'Christmas Island', 'Cocos (Keeling) Islands', 'Colombia', 'Comoros', 'Congo-Brazzaville', 'Congo-Kinshasa', 'Cook Islands', 'Costa Rica', '$_[', 'Croatia', 'Curaçao', 'Cyprus', 'Czech Republic', 'Denmark', 'Djibouti', 'Dominica', 'Dominican Republic', 'East Timor', 'Ecuador', 'El Salvador', 'Egypt', 'Equatorial Guinea', 'Eritrea', 'Estonia', 'Ethiopia', 'Falkland Islands', 'Faroe Islands', 'Federated States of Micronesia', 'Fiji', 'Finland', 'France', 'French Guiana', 'French Polynesia', 'French Southern Lands', 'Gabon', 'Gambia', 'Georgia', 'Germany', 'Ghana', 'Gibraltar', 'Greece', 'Greenland', 'Grenada', 'Guadeloupe', 'Guam', 'Guatemala', 'Guernsey', 'Guinea', 'Guinea-Bissau', 'Guyana', 'Haiti', 'Heard and McDonald Islands', 'Honduras', 'Hong Kong', 'Hungary', 'Iceland', 'India', 'Indonesia', 'Iraq', 'Ireland', 'Isle of Man', 'Israel', 'Italy', 'Jamaica', 'Japan', 'Jersey', 'Jordan', 'Kazakhstan', 'Kenya', 'Kiribati', 'Kuwait', 'Kyrgyzstan', 'Laos', 'Latvia', 'Lebanon', 'Lesotho', 'Liberia', 'Libya', 'Liechtenstein', 'Lithuania', 'Luxembourg', 'Macau', 'Macedonia', 'Madagascar', 'Malawi', 'Malaysia', 'Maldives', 'Mali', 'Malta', 'Marshall Islands', 'Martinique', 'Mauritania', 'Mauritius', 'Mayotte', 'Mexico', 'Moldova', 'Monaco', 'Mongolia', 'Montenegro', 'Montserrat', 'Morocco', 'Mozambique', 'Namibia', 'Nauru', 'Nepal', 'Netherlands', 'New Caledonia', 'New Zealand', 'Nicaragua', 'Niger', 'Nigeria', 'Niue', 'Norfolk Island', 'Northern Mariana Islands', 'Norway', 'Oman', 'Pakistan', 'Palau', 'Panama', 'Papua New Guinea', 'Paraguay', 'Peru', 'Philippines', 'Pitcairn Islands', 'Poland', 'Portugal', 'Puerto Rico', 'Qatar', 'Réunion', 'Romania', 'Russia', 'Rwanda', 'Saint Barthélemy', 'Saint Helena', 'Saint Kitts and Nevis', 'Saint Lucia', 'Saint Martin', 'Saint Pierre and Miquelon', 'Saint Vincent', 'Samoa', 'San Marino', 'São Tomé and Príncipe', 'Saudi Arabia', 'Senegal', 'Serbia', 'Seychelles', 'Sierra Leone', 'Singapore', 'Sint Maarten', 'Slovakia', 'Slovenia', 'Solomon Islands', 'Somalia', 'South Africa', 'South Georgia', 'South Korea', 'Spain', 'Sri Lanka', 'Sudan', 'Suriname', 'Svalbard and Jan Mayen', 'Sweden', 'Swaziland', 'Switzerland', 'Syria', 'Taiwan', 'Tajikistan', 'Tanzania', 'Thailand', 'Togo', 'Tokelau', 'Tonga', 'Trinidad and Tobago', 'Tunisia', 'Turkey', 'Turkmenistan', 'Turks and Caicos Islands', 'Tuvalu', 'Uganda', 'Ukraine', 'United Arab Emirates', 'United Kingdom', 'United States', 'Uruguay', 'Uzbekistan', 'Vanuatu', 'Vatican City', 'Vietnam', 'Venezuela', 'Wallis and Futuna', 'Western Sahara', 'Yemen', 'Zambia', 'Zimbabwe'];

Auto Select Textarea Text

The method selects the entire contents of a text area easily.
<textarea rows="10" cols="50" onclick="this.focus();" readonly="readonly">
   example text

Basic Alert

An alert box is often used if you want to make sure information comes through to the user.

When an alert box pops up, the user will have to click “OK” to proceed.

You just edit the “ALERT!” to whatever you want it to be.

<script type="text/javascript">

Comments in JavaScript

JavaScript comments can be used to explain the code, and make the code more readable.

Single Line Comments

Single line comments start with //.

Any text between // and the end of a line, will be ignored by JavaScript (will not be executed).

For example

var x = 5;      // Declare x, give it the value of 5

Multi-line Comments

Multi-line comments start with /* and end with */.

Any text between /* and */ will be ignored by JavaScript.

The code below will change
the heading with id = "myH"
and the paragraph with id = "myp"
in my web page:

Format Currency

This function will round numbers to two decimal places . For example 33.127 will return 33.13 and 8 will return 8.00

function CurrencyFormatted(amount) {
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;

JavaScript Date

JavaScript Date function is used for display dates dates (years, months, days, minutes, seconds, milliseconds)

<!DOCTYPE html>

<p id="demo"></p>

document.getElementById("demo").innerHTML = Date();


JavaScript Data Types

JavaScript variables can hold many types of data: numbers, text strings, arrays, objects and much more:

var length = 16;                             // Number assigned by a number literal
var points = x * 10;                         // Number assigned by an expression literal
var lastName = "Johnson";                    // String assigned by a string literal
var cars = ["Saab", "Volvo", "BMW"];         // Array assigned by an array literal
var person = {firstName:John, lastName:Doe}; // Object assigned by an object literal

JavaScript Frameworks (Libraries)

JavaScript Frameworks (Libraries) are used for advance level programming in JavaScript. Difficult task like Complex handling of browser differences are handled by JavaScript Libraries. These JavaScript libraries are often called JavaScript frameworks.

Most popular JavaScript frameworks:

  • jQuery
  • Prototype
  • MooTools

All of these frameworks have functions for common JavaScript tasks like animations, DOM manipulation, and Ajax handling.


jQuery is the most popular JavaScript framework on the Internet today. It uses CSS selectors to access and manipulate HTML elements (DOM Objects) on a web page.


Prototype is a JavaScript library that provides a simple for Application Programming Interface to perform common web tasks.


MooTools is also a framework that offers an API to make common JavaScript programming easier.



About The Author

Related Posts

Leave a Reply

Your email address will not be published.