JavaScript Tips and Tricks

by jeremyjones on March 23, 2011

JavaScript is a functional scripting language that is mainly in use as a language for running client-side scripts in a web browser. It is also common in other applications outside of web pages including PDF documents and desktop widgets. The launch of faster JavaScript virtual machines has lead to an increase in the use in server-side web applications.

JavaScript has syntax similar to that of C and takes many of its conventions and names from Java, but it is different to either language. It is actually an implementation of the ECMAScript language that has borrowed the design principles of the Self and Scheme languages.

  1. Joining Strings Together
  2. Assertion
  3. Null, Undefined and Delete
  4. Using Firebug
  5. Objects and Associative Arrays
  6. Type Conversion
  7. Anonymous functions
  8. Polymorphic Functions
  9. Context Object Manipulation
  10. Iteration

{ 0 comments }

Iteration

March 22, 2011

If you have come to JavaScript from a background in Java or C, then you will like the variation on the for loop. It is like the for loop in Perl, Python or PHP but with a little twist. You can use a for loop to repeatedly run a block of script, or once for [...]

Read More

Context Object Manipulation

March 21, 2011

One of the key concepts of JavaScript is the keyword, this, which signifies the JavaScript context object. If you write an inner function, you can access any local variables that you define in the outer function exactly as if you had defined them locally. You can also access any arguments that you pass to a [...]

Read More

Polymorphic Functions

March 21, 2011

It is possible to define multiple functions with the same name in JavaScript, and the last one of those that you define will be the one that runs. This is unlike other languages where you can distinguish between functions by using a different number of arguments when you call the function. Most programmers will only [...]

Read More

Anonymous functions

March 21, 2011

JavaScript allows the use of anonymous functions with full closures. Functions are objects and you can pass them as arguments just like any other object. The scope of a function includes all the names in the scope where it was declared. As you declare functions at run time and local variables can remain after the [...]

Read More

Type Conversion

March 20, 2011

JavaScript has member functions for all objects, such as valueof and toString. When you use literal numbers, Booleans, strings, undefined and null are different from the counterparts that you use for objects. This example shows this: <br /> Typeof new Number(i); // Returns object<br /> Typeof I; // Returns number<br /> There are ways that [...]

Read More

Objects and Associative Arrays

March 20, 2011

The JavaScript Object is very versatile and useful. It works a little like the Object base type in Java and the associative array type like %hash from Perl, dict from Python or array from PHP, and is the best of both worlds. You can also use them for String to Object mapping. You can initialize [...]

Read More