How do I handle cookies

Cookies, JavaScript, Web Development, Client-Side Storage
Learn how to handle cookies in JavaScript for effective client-side storage and data management in web applications.

Handling cookies in JavaScript can be done with the following example:

// Set a cookie document.cookie = "username=JohnDoe;expires=Fri, 31 Dec 2023 23:59:59 GMT;path=/"; // Get a cookie function getCookie(name) { const value = `; ${document.cookie}`; const parts = value.split(`; ${name}=`); if (parts.length === 2) return parts.pop().split(';').shift(); } // Example usage const user = getCookie("username"); console.log(user); // Outputs: JohnDoe // Delete a cookie document.cookie = "username=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/";

Cookies JavaScript Web Development Client-Side Storage