aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes keyword var Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "keyword var" Watch "keyword var" New topic
Author

keyword var

Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Hi, what does it mean to put a var before your variable? How come it also works without it? Thanks!


SCJP 1.5
http://devpinoy.org/blogs/lamia/ - http://everypesocounts.com/
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

To declare (create) a variable, you use the JavaScript statement var (which stands for variable) followed by the name you want to assign the variable.

like
var Flag // Flag is name of variable..


Saifuddin..
[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
Timothy Sam
Ranch Hand

Joined: Sep 18, 2005
Posts: 746
Uhmmm... Yeah, I'm aware of that... But I'm sure I've seen scripts that didn't use that statement...
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1321

just now i create a simple program on javascript without using this statement. its not showing me the value of variable and then i use "var" it's running fine.

it's mean that variable cannot be decaler without use of "var" keyword so how it can works..?

i also want to know if there is a possiblity ?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
In JavaScript you do not have to declare a variabe. If you assign to a variable that has not been declared, it is automaticaloly declared at a global level.

So if you do not use var it is global. If you are expecting that i to be local for your for loop, declare it.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: keyword var