Why I am getting this error though there is no syntax error?What is the reason behind this error?
VM1503:1 Uncaught SyntaxError: Unexpected end of JSON input at JSON.parse ()
<script>
if (localStorage.getItem('cart') == null) {
console.log("NULL");
var cart = [];
} else {
cart = JSON.parse(localStorage.getItem('cart'));
}
$('.cart').click(function() {
console.log("Clicked");
var idstr = this.id.toString()
if (cart[idstr] != undefined) {
cart[idstr] = cart[idstr] + 1
} else {
cart[idstr] = 1
}
localStorage.setItem('cart', JSON.stringify(cart))
console.log(cart);
});
</script>