<!--
{
  "availability" : [
    "tvOS: 9.0.0 - 18.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "TVMLKit",
  "identifier" : "/documentation/TVMLKit/TVApplicationController/evaluate(inJavaScriptContext:completion:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "TVMLKit"
    ],
    "preciseIdentifier" : "c:objc(cs)TVApplicationController(im)evaluateInJavaScriptContext:completion:"
  },
  "title" : "evaluate(inJavaScriptContext:completion:)"
}
-->

# evaluate(inJavaScriptContext:completion:)

Evaluates a block in the JavaScript execution queue.

```
func evaluate(inJavaScriptContext evaluation: @escaping (JSContext) -> Void, completion: (@Sendable (Bool) -> Void)? = nil)
```

## Parameters

`evaluation`

The block to be evaluated in the JavaScript execution queue.

`completion`

The callback after the block has been executed. <doc://com.apple.documentation/documentation/Swift/true> if the block was evaluated; <doc://com.apple.documentation/documentation/Swift/false> otherwise.

## Discussion

> Important:
> You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration:
> 
> ```swift
> func evaluate(inJavaScriptContext evaluation: @escaping (JSContext) -> Void) async -> Bool
> ```
> 
> For information about concurrency and asynchronous code in Swift, see <doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously>.

This method adds a block to the JavaScript execution queue and invokes the completion block after the evaluation block has finished execution. The `context` block parameter is valid within the scope of the evaluation block and should not be referenced by the app outside the block.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)