cab8fdef5e068a512578738976aacc73d4021bee
[yaffs-website] / commands / javascript / evaluate.md
1 evaluate
2 ========
3 Command to evaluate javascript code within the current page you are browsing.
4
5 ##Example of use
6 ####Request
7 ```json
8 {
9     "name": "evaluate",
10     "args": [
11         "(function (fibonnaciNumber) {\n  var looping = function (n) {\n    var a = 0, b = 1, f = 1;\n    for (var i = 2; i <= n; i++) {\n      f = a + b;\n      a = b;\n      b = f;\n    }\n    return f;\n  };\n  return looping(fibonnaciNumber);\n})(10);\n"
12     ]
13 }
14 ```
15 ####Response
16 If there are no javascript errors then the response should be the result of the evaluation of the code, in this case:
17 ```json
18 {
19     "response": 55
20 }
21 ```
22 ##Rule of thumb for javascript code
23 As a recommendation try always to make your code like this:
24 ```javascript
25 (function () {
26   //Here should go all the code you want to evaluate
27   return value;
28 })();
29 ```