pxt-calliope/olddocs/js/code.md

32 lines
1007 B
Markdown
Raw Normal View History

2016-03-26 00:47:20 +01:00
# function
2016-04-02 01:22:47 +02:00
A function with inputs and outputs.
2016-03-26 00:47:20 +01:00
### @parent js/language
To add a **functions** to your script, click the `script` button, then click the `+` `add new function` button
### functions
2016-04-13 17:27:45 +02:00
A **function** takes [inputs](/actionparameters), runs code and (optionally) returns an output.
2016-03-26 00:47:20 +01:00
TouchDevelop functions are similar to `mathematical functions`. Consider the function that computes the square of `x`: `square(x) = x*x`. In code, it would look like this:
```
export function square(x: number) : number {
let result: number
return x * x
return result
}
```
### private function
An function can be marked as **private** in the properties. A private function is not visible outside a library (if the script is a library)
### documentation
2016-04-13 17:27:45 +02:00
The comment(s) at the beginning of a function used to provide a description of its purpose. This text will show in the help area when the function is called from the code editor. This is particularly useful for [libraries](/libraries).
2016-03-26 00:47:20 +01:00