2020-03-16 14:50:12 +08:00
|
|
|
// This script defines a function with two parameters
|
|
|
|
|
|
|
|
let a = 3;
|
|
|
|
|
2016-03-01 21:36:46 -05:00
|
|
|
fn addme(a, b) {
|
2020-03-16 14:50:12 +08:00
|
|
|
a = 42; // notice that 'a' is passed by value
|
|
|
|
a + b; // notice that the last value is returned even if terminated by a semicolon
|
2016-03-01 21:36:46 -05:00
|
|
|
}
|
|
|
|
|
2021-04-09 22:48:47 +08:00
|
|
|
let result = addme(a, 4);
|
2020-05-02 16:23:36 +08:00
|
|
|
|
2021-04-13 14:37:33 +08:00
|
|
|
print(`addme(a, 4) should be 46: ${result}`);
|
2020-05-02 16:23:36 +08:00
|
|
|
|
2021-04-09 22:48:47 +08:00
|
|
|
print(`a should still be 3: ${a}`); // should print 3 - 'a' is never changed
|