title: How to transfer a JSValueRef into a JavaScript var from Objective-C
body: <p>Using JavaScriptCore, if I have an NSString in Objective-C like this:</p>
  
  <pre><code>NSString *objcName = @"Kristof";
  </code></pre>
  
  <p>and a JSGlobalContextRef context called <em>jsContextRef</em>.</p>
  
  <p>How do I transfer the Objective-C value of objcName into a named JavaScript variable in the jsContextRef? I was thinking along the lines of:</p>
  
  <pre><code>JSStringRef jsNameRef = JSStringCreateWithUTF8CString([objcName UTF8String]);
  JSValueRef jsValueRef = JSValueMakeString(jsContextRef, jsNameRef);
  </code></pre>
  
  <p>Let's say the variable name will be "jsName". I need a couple more calls (or maybe even one call), something like:</p>
  
  <pre><code>// This part is pseudo-code for which I would like to have proper code:
  JSValueStoreInVarWithName(jsContextRef,"jsName",jsValueRef);
  </code></pre>
  
  <p>so that in the end this JavaScript will evaluate correctly when called like this in Objective-C:</p>
  
  <pre><code>NSString *lJavaScriptScript = @"var jsUppercaseName = jsName.toUpperCase();";
  JSStringRef scriptJS = JSStringCreateWithUTF8CString([lJavaScriptScript UTF8String]);
  JSValueRef exception = NULL;
  JSValueRef result = JSEvaluateScript(jsContextRef, scriptJS, NULL, NULL, 0, &amp;exception);
  </code></pre>