spacer
Yehuda Shiran May 2, 2002
The Risk of Un-typed Variables
Tips: May 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
OpenOffice 3.2 Lands Amid Critical Changes
Red Hat, IBM Firmly in KVM Virtualization Camp
Red Hat Talks Up Open Source Cloud Plans

JScript .NET's support for un-typed variables makes it very easy to develop short scripts. Novice and occasional developers can focus more on the business logic, rather than being concerned with what types their variables are. The drawback to using un-typed variables is that the results are not always what you would expect. Let's take the following example:

  var x, y, z;
  x = "2";
  y = 2;
  z = x + y;
What do you think the value of z will be? Since we did not declare the types of x and y, the compiler casts one of them to the other. In the case above, z will be 22. The variable y is casted to String and concatenated with x.

To learn more on JScript .NET, go to Column 108, JScript .NET, Part II: Major Features.


People who read this tip also read these tips:

Look for similar tips by subject:


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

webref The latest from WebReference.com Browse >
Are Google's Language Translation Web Services Ready for Prime Time? · Installing and Using Meeplace, the Business Review CMS · Sending an HTML and Plain Text E-newsletter with ASP.NET, Part 2
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Kingston Debuts Power-Saving Memory Upgrades · Web Marketing Tools: What's Your Reputation? · Ecommerce Marketing Tips: Writing Better Copy