here is one... So I'm doing some silverlight and I try to add two 'numbers' right. Javascript is supposed to be not strongly typed language but there are cases where you need to type caste... which normally only shows up in real languages or um strongly typed langauges like say C#. In JavaScript 'type casting' is a bit mucked up but basically there are two types you can try to force things to 'string' or 'number'. The code looks something like this:
var SomeValue = "100";
var SomeNumber = 3;
// alert 1: "1003"
alert( SomeValue + SomeNumber);
// alert 2: "103"
alert( Number(SomeValue) + SomeNumber);
So this is where we can get a way with telling people 1 * 1 may not always equal 2... in this sample the first alert is going to make everything a string where as in the next one we cast the questionable value to a Number and now the math works right...
hmmm... whats the point of a varient if it can't figure out its a number.
Anyway so there is type casting in JavaScript
Monday, 29 October 2007
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment