---
hide_title: false
hide_table_of_contents: false
pagination_next: null
pagination_prev: null
---
import {Fiddle} from '@site/src/components/fiddle';

# toString

The **`toString()`** method returns a string representing the specified Backend value.

## Syntax

```js
toString()
```

### Return value

A string representing the specified Backend value.

## Description

The [Backend](../Backend.mdx) object overrides the `toString()` method of [Object](../../../globals//Object/Object.mdx); it does not inherit
[`Object.prototype.toString()`](../../../globals/Object/prototype/toString.mdx). For [Backend](../Backend.mdx) values, the `toString` method returns the name given to the [Backend](../Backend.mdx) object during construction.

The `toString()` method requires its `this` value to be a [Backend](../Backend.mdx) object.

If the `this` value does not inherit from `Backend.prototype`, a [TypeError](../../../globals/TypeError/TypeError.mdx) is thrown.

## Examples

### Using toString()

The following example logs the string value of a [Backend](../Backend.mdx) object:

<Fiddle config={{
  "type": "javascript",
  "title": "Backend.prototype.toString Example",
  "origins": [
    "https://http-me.fastly.dev"
  ],
  "src": {
    "deps": "{\n  \"@fastly/js-compute\": \"^1.0.1\"\n}",
    "main": `
/// <reference types=\"@fastly/js-compute\" />
import { Backend } from "fastly:backend";
async function app() {
  const backend = new Backend({
    name: "fastly",
    target: "fastly.com",
  });
  console.log(backend.toString()); // "fastly"
}
addEventListener("fetch", event => event.respondWith(app(event)));
`
  },
  "requests": [
    {
      "enableCluster": true,
      "enableShield": false,
      "enableWAF": false,
      "method": "GET",
      "path": "/status=200",
      "useFreshCache": false,
      "followRedirects": false,
      "tests": "",
      "delay": 0
    }
  ],
  "srcVersion": 1
}}>

```js
import { Backend } from "fastly:backend";
async function app() {
  const backend = new Backend({
    name: "fastly",
    target: "fastly.com",
  });
  console.log(backend.toString()); // "fastly"
}
addEventListener("fetch", event => event.respondWith(app(event)));
```

</Fiddle>