I am using below script to read cookie values, it works fine but i want to confirm if this has some syntax error
as when i put this code in VS 2013 it show sytax error red marks around this code
[![const input = "{stamp:'HMzWoJn8V4ZkdRN1DduMHLhS3dKiDDr6VoXCjjeuDMO2w6V+n2CcOg==',necessary:true,preferences:true,statistics:true,marketing:false,ver:1}";
const obj = input
.slice(1, input.length - 1)
.split(',')
.reduce((obj, str) => {
const \[key, val\] = str.split(':');
obj\[key\] = val;
return obj;
}, {});][1]][1]
And when i try to wrap below statement in try catch it show error
try
{
const input = Cookies.get('CookieConsent');
const obj = input
.slice(1, input.length - 1)
.split(',')
.reduce((obj, str) => {
const [key, val] = str.split(':');
obj[key] = val;
return obj;
}, {});
}
catch(err)
{
//do something
}
I am not able to figure out if there is any issue with syntax as it works but possible may be breaking the code logic that i have after this codepen