# tag function

{% hint style="warning" %}
**tag function**'s <mark style="color:yellow;">**first argument**</mark> has a special <mark style="color:purple;">**`raw`**</mark> property, allows you to access the <mark style="color:orange;">**raw strings**</mark> as entered, without processing [escape sequences](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Grammar_and_types#using_special_characters_in_strings).
{% endhint %}

{% tabs %}
{% tab title="💈範例" %}

```javascript
// ⭐️ tag function (template function)
function raw(strings) {
    // ⭐️ first argument (`strings`) has a special `raw` property
    return strings.raw;
}

// ⭐️ tagged templates
raw`line 1 \n line 2`,          // [ 'line 1 \\n line 2' ] (`\n` not escaped)
raw`5 = \n ${2 + 3}!`,          // [ '5 = \\n ', '' ] (`\n` not escaped)

// ⭐️ raw strings
String.raw`5 = \n ${2 + 3}!`,   // '5 = \\n 5!'
String.raw`5 = \n \${2 + 3}!`,   // '5 = \\n \\${2 + 3}!'

// ⭐️ default template function
`5 = \n \${2 + 3}!`,            // 5 = (new line)
                                //  ${2 + 3}!
```

{% endtab %}

{% tab title="📘 手冊" %}

* template literal ⟩ [raw strings](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#raw_strings)
* [String.raw()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/raw) - [tag function](/web/js/val/prim/str/template-literal/tag-function.md) of [template literals](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals).
  {% endtab %}

{% tab title="👥 相關" %}

* [raw string](/web/js/val/prim/str/raw-string.md)
  {% endtab %}
  {% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lochiwei.gitbook.io/web/js/val/prim/str/template-literal/tag-function.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
