Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


JavaScript Tips

Here are some more things I have learnt whilst writing a free game:

1) Some programmers say that it is better to use the expression:

typeof objectProperty === 'undefined'

rather than:

objectProperty === undefined


  • you can confusingly create a variable called 'undefined' or give a value to Javascript's 'undefined' variable

  • you can use the first version with simple Javascript variables that are not set

Also notice that the expression:

null == undefined

is 'true', as Javascript treats a 'null' value quite like an 'undefined' one

2) I have read that it is best not to use the 'caller' property of functions

Using it may make it difficult for Javascript to optimise your code by 'inlining' the functions.

You can find out other ways to help any optimisation by reading about the new 'strict mode' for Javascript

3) I noticed that Internet Explorer (IE) does not allow you to extend HTML elements through their 'prototype'. I understand that IE generally handles HTML elements a little differently to objects of the Javascript language

4) I shorten some built-in function names like this:

Array.prototype.p = Array.prototype.push

I do not change the source code but make the changes in my 'minimising' scripts.

If you use a 'for in' loop on arrays, you will need to stop the alias appearing by using the 'hasOwnProperty()' function. Any libraries you use will need to do this too

5) If you miss out an element in a list of array elements, e.g. 'a = [1,,3]', then you get an element with a value of 'undefined'.

I typed this by mistake and got an error in my code

You can find more tips in the wiki of the British Bingo project on Sourceforge

Posted by Bert Beckwith 2013-05-28