Flag Types
The four value types
Section titled “The four value 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.
Boolean
Section titled “Boolean”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);String
Section titled “String”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.Number
Section titled “Number”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 GrowthBookThe 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.
Comparing the types at a glance
Section titled “Comparing the types at a glance”| Type | SDK return | Best for |
|---|---|---|
| Boolean | true / false | Feature gates, kill switches |
| String | any string | Copy variants, layout names |
| Number | any number | Thresholds, limits, prices |
| JSON | any object or array | Config bundles, multi-property settings |
Hoisted SDK snippet — JSON flag
Section titled “Hoisted SDK snippet — JSON flag”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