Skip to content

Flag Types

When you create a Feature in GrowthBook you choose one of four value types. The type is permanent — you cannot change it after creation, so choose deliberately.

The simplest type: true or false.

Use it when you need a simple on/off gate — show a new UI, enable a payment method, unlock a beta feature.

if (gb.isOn('dark-mode')) {
enableDarkMode();
}
// or with explicit fallback:
const isDark = gb.getFeatureValue('dark-mode', false);

A text value returned as-is from the SDK.

Use it when you need to vary copy, pick a variant name, or return a configuration string.

const buttonLabel = gb.getFeatureValue('cta-text', 'Get started');
// returns 'Get started', 'Try for free', 'Sign up now', etc.

A numeric value (integer or float).

Use it when you want to tune a threshold, price, limit, or percentage without a code deploy.

const maxItems = gb.getFeatureValue('cart-max-items', 10);
// returns 10, 20, 50, etc.

An arbitrary JSON object or array.

Use it when you need to ship a whole configuration blob — button colours, pricing tiers, UI layout options — as a single flag.

const theme = gb.getFeatureValue('ui-theme', { color: 'blue', size: 'md' });
// theme.color, theme.size come from GrowthBook

The fallback argument to getFeatureValue must be a valid JS object that matches the shape you expect from GrowthBook. If GrowthBook is unreachable, your app still works with the fallback.

TypeSDK returnBest for
Booleantrue / falseFeature gates, kill switches
Stringany stringCopy variants, layout names
Numberany numberThresholds, limits, prices
JSONany object or arrayConfig bundles, multi-property settings
import { GrowthBook } from '@growthbook/growthbook';

const gb = new GrowthBook({
  apiHost: 'https://cdn.growthbook.io',
  clientKey: 'sdk-YOUR_DEV_KEY',
});

await gb.init({ timeout: 2000 });

// JSON flag — always pass a complete fallback object
const config = gb.getFeatureValue('ui-theme', { color: 'blue', size: 'md' });

console.log(config.color); // 'blue' or whatever GrowthBook returns
console.log(config.size);  // 'md' or whatever GrowthBook returns
Which value type should you use for a simple feature gate (show/hide a UI element)?
What does gb.getFeatureValue("cart-max-items", 10) return when GrowthBook is unreachable?
Can you change a Feature's value type after it has been created in GrowthBook?
Which value type is best for shipping a multi-property configuration (e.g. colour, size, layout)?