Skip to Content
NFSFU234FormValidation v3 is here — file upload validation, config-driven rules, and more.
v2 (legacy)checkVariableType

checkVariableType

The checkVariableType function checks the type of a given variable and returns a string that represents its type. If the type cannot be determined, it returns 'unknown'.

Works in: HTML5, React JS, Node.js

ParameterTypeDefaultDescription
variableanyundefinedThe variable whose type needs to be checked.

Usage

Example: Check Variable Type

const type1 = nfsfu234FormValidation.checkVariableType("Hello"); // "string" const type2 = nfsfu234FormValidation.checkVariableType(123); // "number" const type3 = nfsfu234FormValidation.checkVariableType([]); // "array" const type4 = nfsfu234FormValidation.checkVariableType({}); // "object" const type5 = nfsfu234FormValidation.checkVariableType(() => {}); // "function" const type6 = nfsfu234FormValidation.checkVariableType(null); // "null" const type7 = nfsfu234FormValidation.checkVariableType(undefined); // "undefined" const type8 = nfsfu234FormValidation.checkVariableType(document.body); // "HTML Element"

See also

Last updated on