---
title: "JSValueToNumber(_:_:_:)"
framework: javascriptcore
role: symbol
role_heading: Function
path: "javascriptcore/jsvaluetonumber(_:_:_:)"
---

# JSValueToNumber(_:_:_:)

Converts a JavaScript value to a number and returns the resulting number.

## Declaration

```swift
func JSValueToNumber(_ ctx: JSContextRef!, _ value: JSValueRef!, _ exception: UnsafeMutablePointer<JSValueRef?>!) -> Double
```

## Parameters

- `ctx`: The execution context to use.
- `value`: The doc://com.apple.javascriptcore/documentation/JavaScriptCore/JSValueRef to convert.
- `exception`: A pointer to a doc://com.apple.javascriptcore/documentation/JavaScriptCore/JSValueRef to store an exception in, if any. Pass NULL to discard any exception.

## Return Value

Return Value The numeric result of conversion, or NaN if the system throws an exception.

## See Also

### Converting to Primitive Values

- [JSValueToBoolean(_:_:)](javascriptcore/jsvaluetoboolean(_:_:).md)
- [JSValueToStringCopy(_:_:_:)](javascriptcore/jsvaluetostringcopy(_:_:_:).md)
- [JSValueToObject(_:_:_:)](javascriptcore/jsvaluetoobject(_:_:_:).md)
