This question is actually more about javascript. I've just started learning it and I'm a Java developer, so some things in JS seem unclear to me.
I'm working on a chrome extension and trying to call chrome's storage API like this
const key = 'myKey';
const value = { name: 'my value' };
chrome.storage.local.set({key: value}, () => {
console.log('Stored name: ' + value.name);
});
I can see that const key
is greyed out, so in the curly braces {key: value}
the constant variable is not the one being used. I also tried to change it to {blabla: value}
and blabla
is still shown as an existing variable in the IDE. It doesn't go to any declaration when I try to, but still it's a weird behaviour. I'm not sure which JS concept I should research about in order to understand this. Thanks!
UPD: now it became even weirder. I tried out some things and got it working for my specific scenario, but how it works is still a mystery to me. So, when saving the key-value pair the following way
chrome.storage.sync.set({testKey: value}, function() {
console.log('Value is set to ' + value);
});
and reading it like
chrome.storage.sync.get(['testKey'], function (result) {
console.log('Value currently is ' + result.testKey);
});
Then I'm getting the (un)expected output in console.