Closed Thread Icon

Preserved Topic: A variabel question (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=18241" title="Pages that link to Preserved Topic: A variabel question (Page 1 of 1)" rel="nofollow" >Preserved Topic: A variabel question <span class="small">(Page 1 of 1)</span>\

 
Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-17-2001 14:44

Just wondering what variabels that is in javascript, and how does they work?



Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-17-2001 15:22

A variable stores a single peice of information. Like, a number or a "string." I'm sure you've seen this before. For instance:

var myvariable = 3; // myvariable stores the value 3
myvariable = myvariable + 2; // myvariable stores the value 5
alert(myvariable*2); // shows the number 10

var mystring = "Slime"; // mystring stores the string "Slime"
mystring = mystring + " is cool"; // mystring stors the string "Slime is cool"
alert(mystring + ", or maybe not."); // shows, "Slime is cool, or maybe not."

[This message has been edited by Slime (edited 08-17-2001).]

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 08-17-2001 15:26

Variables can be just about anything. They can hold any form of data that will be used in your script. Check out WebMonkey.

C:\

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-17-2001 15:26

Yes I have seen this before, but when I was programming inn Pascal and Delphi, there vas different type of variables like this

var
dim
int
public

And they all work inn different ways
do you know wat kind of variables there is inn javascript





Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-17-2001 15:35

Oh, the cool (and sometimes confusing) thing about JavaScript, is that it deals with all that stuff by itself. A variable can be any number (integer, long, double, you name it) or a string, or an object or an array. This, for example, is perfectly legal:

var myvar = 3;
var mystring = "5";
alert(myvar + mystring); // says 8, since the number came first, it added them like numbers.
alert(mystring + myvar); // says 53, since the string came first, it concatenated them like strings.

JavaScript deals with all the necessary conversions itself. As a result, it certainly isn't as *fast* as those languages you mentioned, but we rarely need it to be that fast.

I believe "var" stands for "variant."

Osaires
Paranoid (IV) Inmate

From: oslo, Norway
Insane since: Aug 2001

posted posted 08-17-2001 15:43

Hmm. this is not right it.

Sorry about this but my explaining is not the best
is "var" the only way to define a variable inn JavaScript?



Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 08-17-2001 15:51

Yup, it is. Don't think of it as a single data type, think of it as *all* data types in one. You just never need to specify which data type you want your variable to be, because the browser running the JavaScript will figure it out on its own.

In fact, the keyword "var" isn't even necessary. It's good practice to put it at the first place a variable is defined, but you can just start using a variable at any time without worrying about whether it's been defined - again, JavaScript will create the variable itself once you start using it.

JavaScript is an "untyped" language. And it's very loose about things like syntax, too - semicolons are only required if you have multiple statements on one line, for instance. (Put them in anyway, it makes things cleaner.)

« BackwardsOnwards »

Show Forum Drop Down Menu