JS.EvaluateToString
-------------------

Evaluates a JavaScript expression.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [JavaScript](component_JavaScript.md) | [10.0](newinversion100.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "JS.EvaluateToString"; JSRef; JavaScript ) 

**MBS**( **"JS.EvaluateToString";** /\* Evaluates a JavaScript expression. \*/  
**$JSRef**; /\* The JavaScript reference number.e.g. $js \*/   
**$JavaScript**) /\* A JavaScript expression.e.g. "1+2" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| JSRef | The JavaScript reference number. | $js |
| JavaScript | A JavaScript expression. | "1+2" |

### Result

Returns text or error.

### Description

Evaluates a JavaScript expression.  
This may include definition of functions and objects and using them.  
Result is converted to string and returned.  
### Examples

Evaluate some text:

 Set Variable \[ $js ; Value: MBS ( "[JS.New](JSNew.md)" ) \]   
Set Variable \[ $r ; Value: MBS ( "JS.EvaluateToString"; $js ; "e = \\"test\\"; e + String.fromCharCode(33)") \]   
Show Custom Dialog \[ "Result" ; $r \]   
Set Variable \[ $r ; Value: MBS ( "[JS.Release](JSRelease.md)"; $JS ) \]  
Defines and runs a function in JavaScript:

 Let(\[  
f = "  
function makeCRCTable(){  
 var c;  
 var crcTable = \[\];  
 for(var n =0; n &lt; 256; n++){  
 c = n;  
 for(var k =0; k &lt; 8; k++){  
 c = ((c&amp;1) ? (0xEDB88320 ^ (c &gt;&gt;&gt; 1)) : (c &gt;&gt;&gt; 1));  
 }  
 crcTable\[n\] = c;  
 }  
 return crcTable;  
}  
  
function crc32(str) {  
 var crcTable = crcTable || (crcTable = makeCRCTable());  
 var crc = 0 ^ (-1);  
  
 for (var i = 0; i &lt; str.length; i++ ) {  
 crc = (crc &gt;&gt;&gt; 8) ^ crcTable\[(crc ^ str.charCodeAt(i)) &amp; 0xFF\];  
 }  
  
 return (crc ^ (-1)) &gt;&gt;&gt; 0;  
};  
  
crc32(InputValue);";  
j = MBS ( "[JS.New](JSNew.md)" );  
r = MBS ( "[JS.SetGlobalPropertyValue](JSSetGlobalPropertyValue.md)"; j; "InputValue"; "Hello World" );  
r = MBS ( "JS.EvaluateToString"; j; f );  
x = MBS ( "[JS.Release](JSRelease.md)"; j )  
\];r)  
### See also

- [JavaScript.EvaluateScript](JavaScriptEvaluateScript.md)
- [JS.Evaluate](JSEvaluate.md)
- [JS.New](JSNew.md)
- [JS.Release](JSRelease.md)
- [JS.SetGlobalProperty](JSSetGlobalProperty.md)
- [JS.SetGlobalPropertyValue](JSSetGlobalPropertyValue.md)

### Example Databases

- [JavaScript/CoordinatDistance](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/CoordinatDistance.shtml#5ScriptAnchor_)
- [JavaScript/JavaScript libPhoneNumber](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript%20libPhoneNumber.shtml#9ScriptAnchor_)
- [JavaScript/JavaScript SunCalc](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript%20SunCalc.shtml#9ScriptAnchor_)
- [JavaScript/JavaScript](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/JavaScript.shtml#9ScriptAnchor_)
- [JavaScript/RichTextToJSON](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/JavaScript/RichTextToJSON.shtml#15CustomFunctionAnchor_)

### Blog Entries

- [FileMaker and JavaScript - the perfect combination](https://www.mbsplugins.de/archive/2020-02-03/FileMaker_and_JavaScript_-_the/monkeybreadsoftware_blog_filemaker)
- [Our JavaScript engine for FileMaker](https://www.mbsplugins.de/archive/2019-12-09/Our_JavaScript_engine_for_File/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 4/2021, Seite 20](https://filemaker-magazin.de/neuigkeit/4152-Appetithappen-FMM_202104)

This function checks for a license.

Created 7th December 2019 , last changed 8th July 2021

  
[JS.Evaluate](JSEvaluate.md) - [JS.GetGlobalProperty](JSGetGlobalProperty.md)

[HTML Version](JSEvaluateToString.shtml)