Update netscriptfunctions.rst

This commit is contained in:
JJ 2018-02-20 14:56:18 -05:00 committed by GitHub
parent 6713dca1d6
commit f99b897ac4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -861,6 +861,26 @@ The example above prints the following in its log::
15 15
11 11
For those with experience in other languages, especially Javascript it may be important to note that function declarations are not hoisted and must be declared BEFORE you use them.
print(hello());
function hello() {
return "world";
}
Will cause an error saying `variable hello not defined` whereas::
function hello() {
return "world";
}
print(hello());
Will print out
world
**Note about variable scope in functions:** **Note about variable scope in functions:**
Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables. Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables.