---
title: "evaluateScript(_:withSourceURL:)"
framework: javascriptcore
role: symbol
role_heading: Instance Method
path: "javascriptcore/jscontext/evaluatescript(_:withsourceurl:)"
---

# evaluateScript(_:withSourceURL:)

Executes the specified JavaScript code, treating the specified URL as its source location.

## Declaration

```swift
func evaluateScript(_ script: String!, withSourceURL sourceURL: URL!) -> JSValue!
```

## Parameters

- `script`: The JavaScript source code to evaluate.
- `sourceURL`: A URL to be considered as the script’s origin.

## Return Value

Return Value The last value generated by the script. Note that a script can result in the JavaScript value undefined.

## Discussion

Discussion Evaluating a script runs any top-level code and adds function or object definitions to the context’s global object. The sourceURL parameter is informative only; debuggers may use this URL when reporting exceptions.

## See Also

### Evaluating scripts

- [evaluateScript(_:)](javascriptcore/jscontext/evaluatescript(_:).md)
