https://www.growthbook.io/ logo
c

cuddly-journalist-11507

03/20/2023, 8:45 PM
Hello there, I have a question about the best way to execute the variation. To check if the feature is on and the current variation the best way to execute the code is this way?
Copy code
gb.loadFeatures().then(function() {
  if (gb.isOn("widget") && variationId == 1) {
    document.getElementById("gb_with-widget").style.display = 'flex'
    document.getElementById("gb_no-widget").remove()
  }
}
f

fresh-football-47124

03/20/2023, 8:53 PM
is “widget” a boolean feature?
Assuming it is, that ‘isOn’ will be true or false depending on if its the control (off) or the second variation (on)
(by default, you can adjust this in the UI)
c

cuddly-journalist-11507

03/21/2023, 1:35 PM
Hmm, I debugged in console that the 2 variations is executing the code inside the
isOn
, if the id variation is 0 (default/control variation) doesn't should execute the code?