<!--
{
  "availability" : [
    "iOS: 7.0.0 -",
    "iPadOS: 7.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.9.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "JavaScriptCore",
  "identifier" : "/documentation/JavaScriptCore/JSContext/evaluateScript(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "JavaScriptCore"
    ],
    "preciseIdentifier" : "c:objc(cs)JSContext(im)evaluateScript:"
  },
  "title" : "evaluateScript(_:)"
}
-->

# evaluateScript(_:)

Executes the specified JavaScript code.

```
func evaluateScript(_ script: String!) -> JSValue!
```

## Parameters

`script`

The JavaScript source code to evaluate.

## Return Value

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

## Discussion

Evaluating a script runs any top-level code and adds function and object definitions to the context’s global object.

---

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)