Files
30-seconds-of-code/snippets/serializeCookie.md
Isabelle Viktoria Maciohsek 5cb69e3c5c Update snippet descriptions
2020-10-22 20:24:30 +03:00

18 lines
386 B
Markdown

---
title: serializeCookie
tags: browser,string,intermediate
---
Serializes a cookie name-value pair into a Set-Cookie header string.
- Use template literals and `encodeURIComponent()` to create the appropriate string.
```js
const serializeCookie = (name, val) =>
`${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
```
```js
serializeCookie('foo', 'bar'); // 'foo=bar'
```