mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-09 17:23:53 +01:00
Update netscriptfunctions.rst
This commit is contained in:
parent
6713dca1d6
commit
f99b897ac4
@ -861,6 +861,26 @@ The example above prints the following in its log::
|
||||
15
|
||||
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:**
|
||||
|
||||
Functions can access "global" variables declared outside of the function's scope. However, they cannot change the value of any "global" variables.
|
||||
|
Loading…
Reference in New Issue
Block a user