[thelist] One more request...

Tom Dell'Aringa pixelmech at yahoo.com
Thu Mar 13 12:44:57 CST 2003


Hi all,

I wanted to ask one more time if any freelancers out there could
share some tips or techniques on how they get and sell their work. I
am writing a chapter for an upcoming tech book on the subject.

I was surprised to only get *one* response! Now I KNOW there is more
than ONE freelancer on this list! :o) C'mon - help your fellow and
upcoming freelancers! I'm sure I don't have all the bases covered.
Also, things you think *don't* work would be helpful too.

Tom

<tip="javascript variable scope" author="pixelmech">

Something that often trips up beginning (and sometimes experienced)
programmers is variable scope. (I'm talking specifically JS here, but
it does apply to other languages).

There are times when you want a "global" variable, you want every
script/function on your page to access that value. There are times
when you only need a variable to work within a single function. That
is a "local" variable. 

To set a global variable, you set it OUTSIDE any function in your
script tag:

<script>
var myGlobalVar = foo;

function someFunction() {...}
</script>

Now myGlobalVar is available to any function on that page, and you
can set it and get it's value.

However, if you set it INSIDE your function:

<script>
function someFunction()
{
  var myGlobalVar = foo;
}
</script>

Then you cannot access that value anywhere but within that function.
It has "local scope". 

Note the 'var' keyword is optional, and there are different opinions
on whether you should use it or not. For myself, I tend to use it
when I am setting a global page variable.

NOTE: If/when you leave that page - ALL your variables are destroyed
unless you pass them on somehow. Even a global variable resets itself
on page load.

</tip>

=====
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
http://www.pixelmech.com/
var me = tom.pixelmech.webDeveloper();

http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
http://webhosting.yahoo.com


More information about the thelist mailing list