# Type conversion

Any value from SurrealDB is converted into a JavaScript type automatically, and the return value from the JavaScript function is converted to a SurrealQL value.

Any value from SurrealDB is converted into a JavaScript type automatically, and the return value from the JavaScript function is converted to a SurrealQL value. Boolean values, Integers, Floats, Strings, Arrays, Objects, and Date objects are all converted automatically to and from SurrealQL values.

```surql
CREATE user:test SET created_at = function() {
	return new Date();
};
```

```surql title="Output"
[
	{
		created_at: d'2026-04-02T01:13:18.408Z',
		id: user:test
	}
]
```

In addition, a number of special classes are included within the JavaScript functions for the additional types which are not built into JavaScript. These enable the creation of [`duration`](/docs/reference/query-language/language-primitives/data-types/datetimes.md#durations-and-datetimes) values, [`record`](/docs/reference/query-language/language-primitives/data-types/record-ids.md) ids, and [`UUID`](/docs/reference/query-language/language-primitives/data-types/strings.md#uuid) values from within JavaScript.

Any values of these types passed into embedded scripting functions are also represented with these special classes.

```surql
CREATE user:test SET
	session_timeout = function() {
		return new Duration('1w');
	},
	best_friend = function() {
		return new Record('user', 'joanna');
	},
	identifier = function() {
		return new Uuid('03412258-988f-47cd-82db-549902cdaffe');
	}
;
```

```surql title="Output"
[
	{
		best_friend: user:joanna,
		id: user:test1,
		identifier: u'03412258-988f-47cd-82db-549902cdaffe',
		session_timeout: 1w
	}
]
```
