Pages

July 8, 2010

Type hinting in JavaScript variables

JavaScript is a loosely typed language and has no notion of type hinting. Anyway, we can mimic this behavior by prefixing our variables with some letters that serve as a reminder to developers. Here are some prefixes:

Type prefixes
Prefix Type
o Object
s String
a Array
n Number

Some examples:

var aTest = ['a', 'b', 'c'];
var sBar = 'Bar';
var oFoo = new Foo();

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.