Connecting Tech Pros Worldwide Forums | Help | Site Map

Variable Types within a Function

Scuttlejo
Guest
 
Posts: n/a
#1: Jul 23 '05

I'm trying to define variable types within a function (Ex:
first:String) and I'm receiving error messages when trying to run the
code. Is there anything I'm doing wrong? Is there anything with the
String type that's missing?


Martin Honnen
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Variable Types within a Function




Scuttlejo wrote:
[color=blue]
> I'm trying to define variable types within a function (Ex:
> first:String) and I'm receiving error messages when trying to run the
> code. Is there anything I'm doing wrong? Is there anything with the
> String type that's missing?[/color]

You can't declare the type of variables or function parameters in
JavaScript 1.x, there is no syntax for that. So unless you happen to use
JScript.NET the notation
varname: typeName
does not work. Not sure where you got the idea.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Lee
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Variable Types within a Function


Scuttlejo said:[color=blue]
>
>
> I'm trying to define variable types within a function (Ex:
>first:String) and I'm receiving error messages when trying to run the
>code. Is there anything I'm doing wrong? Is there anything with the
>String type that's missing?[/color]

I get the impression that you've been reading proposed standards,
rather than documentation of any currently implemented version of
Javascript. You can't declare variable types.

The FAQ for this newsgroup (posted frequently) should point you
towards some better sources.

Danny
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Variable Types within a Function




Well, in js the way you'd TYPE it will be:

var varname=new String();
var anothervar=new Number();

and so on, however, you can also just give it an assignment and it'll be
CLASSED according to the data used.

Danny



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Lee
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Variable Types within a Function


Danny said:[color=blue]
>
>
>
> Well, in js the way you'd TYPE it will be:
>
> var varname=new String();
> var anothervar=new Number();[/color]

That's not as useful as you may think:

var varname=new String();
varname="this string";

creates a String object, and then discards that object,
replacing it with a simple string.

You should always quote the relevant part of the message
you're responding to, and put your response *after* the
quoted portion. That's the standard for this newsgroup.

Closed Thread