Browser side scripting language.
typeof
typeof
can be used to find the datatype of a particular variable. e.g. if you run:
var i = "12";
var iType = typeof i;
var j = 12;
var jType = typeof j;
alert("iType: " + iType);
alert("jType: " + jType);
You will get the following 2 alerts:
iType: string
jType: number
Yahoo UI (YUI)
We’ve used the YUI toolkit to help with some design and coding of front end user interfaces. Its very neat and relatively easy to setup. Visit the official YUI library for more information.
Objects and their properties
Below is an example of initializing objects and modifying their properties.
// create empty object
var exampleObject = {};
// create apple with some properties
var apple = {
colour: "green",
price: 1.25,
variety: "granny smith"
};
// change the apple's colour to red using square brackets and quotes.
apple["colour"] = "red";
// change it back to green using dot notation.
apple.colour = "green";
// add a new property
apple.weightInGrams = 300;
// delete the new property
delete apple.weightInGrams;
// enumerate through all properties of the apple
for (name in apple) {
document.write(name + ": " + apple[name]);
}
The above will output
colour: green
price: 1.25
variety: granny smith
Strings
String substitution with Regular Expressions
Use the String replace
method. Regular expressions are part of standard JavaScript.
"a/long/dir/filename.mp3".replace(/^.*\//, "")
will return
"filename.mp3"