Question 17
Consider the following JavaScript code.
function addItemToCart(item) { let cart = JSON.parse(localStorage.getItem('cart')) || []; cart.push(item); localStorage.setItem('cart', JSON.stringify(cart)); }
function getCartItems() { return JSON.parse(localStorage.getItem('cart')) || []; }
addItemToCart({ id: 1, name: 'Laptop' }.name); console.log(getCartItems());The above code is initially loaded on the browser and then the browser is refreshed two times. What will be the final output?