How to set data in cookies using JavaScript

In this short article, we will show you how to set data in cookies using JavaScript.

Create a cookie

Use the document.cookie property to create a cookie using JavaScript.

Create a cookie and set an expiry date

You can set an expiry date and time (in UTC time) to make the cookie alive. By default, the cookie is deleted once the browser is closed.

Cookie with a path parameter

By default, the cookie belongs to the current page. With a path parameter, you can tell the browser what path the cookie belongs to.

In the upcoming article, we will see how to read the cookies from the browser using JavaScript.

That’s it for today.
Thank you for reading. Happy Coding..!! 🙂

If you found value in this article,
you can support us by buying me a coffee! ☕

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *