Samyak Samyak - 6 months ago 45
Javascript Question

How to negate a variable which is in

I need to negate/toggle the boolean value of a variable which is in but it's throwing an error:

var toggle ='toggle');{ "toggle": !toggle }, function() {
console.log('Settings saved');

I tried getting the variable first but it's showing an error: Invocation of form get(string) doesn't match definition get(optional string or array or object keys, function callback).
Any help appreciated!

Answer Source

Since reading is asynchronous we need to use a callback (hence the error message):"toggle", function(data) {               // async callback
  // check for errors via runtime.lastError

  // update settings{"toggle": !data.toggle}, function() { // invert and set
    // check for errors via runtime.lastError
    // Notify that we saved.
    console.log('Settings saved');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download