Todays JavaScript Gem comes to us from Scott Andrews new blog, The Strange Zen of JavaScript.
There are two ways to declare variables within JavaScript. One is private, meaning that it can be used/availabe only within that function. The other is public, meaning that it can be used outside of that function.
The Global way to declare:
function Foo(){
bar = 1;
}
The Private way:
function Foo() {
var bar = 1;
}
See the difference? Variables declared without the var operator are global by default.
Tagged As Coding, Javascript, Reference, Tip
Comments are Open (2)
Posted at 11:33 AM
Comments
Keith
Along with this a good habbit to get into is to not use global variables unless you need to return more than one value. The return method is your friend!
Posted by: Keith | May 4, 2005 10:44 AM
imran
Hi
I did like your blog postings and comments but i have soem problem if some1 could help me out.
Does anyone know how to pass html table data from parent to a child form html table ? Or may be you could let me know any URL related to this topic.
Any kind of help is highly appericiated.
Thanks
Imran Hashmi
http://www.visionstudio.co.uk
Posted by: imran | November 4, 2005 07:03 AM