I'm working with the javascript SDK and running in...
# ask-questions
r
I'm working with the javascript SDK and running into an issue with features returning a null value rather than any expected value. GB object returns when I console.log(gb) however looking inside that object, the features return null values. When I try to use gb.isOn("my-feature") it always returns false. Am I missing something in my code, or is something likely wrong with my set up?
Copy code
const gb = new GrowthBook({
            apiHost: "<https://cdn.growthbook.io>",
            clientKey: "sdk-z2eQdvHSoRomlSFH",
            // Enable easier debugging during development
            enableDevMode: true,
            // Update the instance in realtime as features change in GrowthBook
            subscribeToChanges: true,
            // Only required for A/B testing
            // Called every time a user is put into an experiment
            trackingCallback: (experiment, result) => {
              console.log("Experiment Viewed", {
                experimentId: experiment.key,
                variationId: result.key,
              });
            },
          });

          
          // Use an async function to initialize GrowthBook
          async function initializeGrowthBook() {
            // Download features and experiments from the CDN
            await gb.init();
            console.log("GrowthBook initialized");
          }
          
          initializeGrowthBook(); // Call the async function
          console.log(gb);
          if (gb.isOn("my-feature")) {
            console.log("Feature enabled!");
          }
p
You'll need to wait till gb is initallized to check for the feature flag. Simplest thing to do would be to move the check for the feature right under
console.log("GrowthBook initialized");
r
@plain-scooter-8648 thank you. Only now, they're evaluating as "true" every time when the experiment running should be rendering them as true sometimes and false other times, what am I doing wrong?
p
I would first check the rules on your feature flag to make sure there's nothing that would be making your browser always get the feature flag on. (keep in mind that experiments are sticky to the assignment ID so once your are in an experiment you'll always receive the same value for the feature flag, You might need to login with a different test account or view your site from the private window)
r
Thank you @plain-scooter-8648 thats very helpful. One more question, I set up a new experiment with a new feature with numbers. The features default value is 15, but the 2 different groups in the experiment should return either the numbers 7 or 8. Currently, I can only find in the documentation gb.getFeatureValue() which returns the default value 15--rather than the value from the experiment. The experiment is running. Is there a specific method in the javascriptSDK that allows me to access the given value of a feature flag when put into an experiment?
it almost seems like as I test it, I'm never actually getting put into an experiment?