JavaScript
typeOf()

typeOf()

The typeOf() method returns the type of variables.

Usage

import { typeOf } from '@ponsetya/core'

Syntax

typeOf(value: unknown): Type

Parameters

Parameters

value: unknown
The value whose type is to be determined.
Returns: Type
A string representing the type of the value.

Examples

console.log(typeOf('x')) // 'string'
console.log(typeOf([])) // 'array'
console.log(typeOf({})) // 'object'
console.log(typeOf(/^[5x]+$/)) // 'regexp'
console.log(typeOf(5)) // 'number'
console.log(typeOf(NaN)) // 'NaN'
console.log(typeOf(null)) // 'null'
console.log(typeOf(undefined)) // 'undefined'

Type Aliases

Primitive Type

export type PrimitiveType =
  | 'string'
  | 'number'
  | 'bigint'
  | 'boolean'
  | 'undefined'
  | 'symbol'
  | 'null'

Object Type

export type ObjectType = 'function' | 'object' | 'array' | 'regexp' | 'NaN'

Type

export type Type = PrimitiveType | ObjectType