<!--
{
  "availability" : [
    "iOS: 16.0.0 -",
    "iPadOS: 16.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.5.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSEvaluateScript(_:_:_:_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:@F@JSEvaluateScript"
  },
  "title" : "JSEvaluateScript(_:_:_:_:_:_:)"
}
-->

# JSEvaluateScript(_:_:_:_:_:_:)

Evaluates a string of JavaScript.

```
func JSEvaluateScript(_ ctx: JSContextRef!, _ script: JSStringRef!, _ thisObject: JSObjectRef!, _ sourceURL: JSStringRef!, _ startingLineNumber: Int32, _ exception: UnsafeMutablePointer<JSValueRef?>!) -> JSValueRef!
```

## Parameters

`ctx`

The execution context to use.

`script`

A [`JSStringRef`](/documentation/JavaScriptCore/JSStringRef) that contains the script to evaluate.

`thisObject`

The object to use as `this` or `NULL` to use the global object as `this`.

`sourceURL`

A [`JSStringRef`](/documentation/JavaScriptCore/JSStringRef) that contains a URL for the script’s source file. The system only uses this when reporting exceptions. Pass `NULL` to omit source file information in exceptions.

`startingLineNumber`

An integer value that specifies the script’s starting line number in the file at `sourceURL`. The system only uses this when reporting exceptions.

`exception`

A pointer to a [`JSValueRef`](/documentation/JavaScriptCore/JSValueRef) to store an exception in, if any. Pass `NULL` to discard any exception.

## Return Value

The value that results from evaluating `script`, or `NULL` if the system throws an exception.

---

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)