JS Built-ins
TypeScriptbeginner

Type Guard β€” isBoolean

πŸ“– Usage Example
function isBoolean(x: unknown): x is boolean {
  return typeof x === 'boolean'
}
isBoolean(true)   // β†’ true
isBoolean(1)      // β†’ false

typeof x === 'boolean' checks for exactly true or false, not truthy/falsy values.

Type Guards: isBoolean

Challenge: Implement isBoolean(x: unknown): x is boolean.

isBoolean(true)   // β†’ true
isBoolean(false)  // β†’ true
isBoolean(1)      // β†’ false  (1 is truthy, not boolean)
πŸ’‘ Hints (1)
  • β€’ typeof x === "boolean" narrows to exactly true or false.