---
title: "evaluateJavaScript(_:completionHandler:)"
framework: webkit
role: symbol
role_heading: Instance Method
path: "webkit/wkwebview/evaluatejavascript(_:completionhandler:)"
---

# evaluateJavaScript(_:completionHandler:)

Evaluates the specified JavaScript string.

## Declaration

```swift
func evaluateJavaScript(_ javaScriptString: String, completionHandler: (@MainActor @Sendable (Any?, (any Error)?) -> Void)? = nil)
```

```swift
func evaluateJavaScript(_ javaScriptString: String) async throws -> Any?
```

## Parameters

- `javaScriptString`: The JavaScript string to evaluate.
- `completionHandler`: A handler block to execute when script evaluation finishes. The method calls your block whether script evaluation completes successfully or fails. The block has no return value and takes the following parameters:

## Discussion

Discussion After evaluating the script, this method executes the completion handler block with either the result of the script evaluation or an error. The completion handler always runs on the app’s main thread.

## See Also

### Executing JavaScript

- [evaluateJavaScript(_:in:in:completionHandler:)](webkit/wkwebview/evaluatejavascript(_:in:in:completionhandler:).md)
- [evaluateJavaScript(_:in:contentWorld:)](webkit/wkwebview/evaluatejavascript(_:in:contentworld:).md)
- [callAsyncJavaScript(_:arguments:in:in:completionHandler:)](webkit/wkwebview/callasyncjavascript(_:arguments:in:in:completionhandler:).md)
- [callAsyncJavaScript(_:arguments:in:contentWorld:)](webkit/wkwebview/callasyncjavascript(_:arguments:in:contentworld:).md)
