typeOf() See also

typeOf()

import { typeOf } from "@fed1/jsos";

Likely the most important JSFunction in JSOS's type system. The typeOf() function returns the JSOS type of any value given to it.

Some examples:

typeOf("foo") === JSString
typeOf(["foo"]) === JSArray
typeOf({}) === JSObject
typeOf(null) === JSNull
typeOf(JSNull) === TJSType
typeOf(TJSType) === TType
typeOf(explain) === TGeneric

As you can see, it bridges the "divide" between JavaScript types and JSOS types seamlessly.

What you get back by calling this function is not the type name but the type object of a value. If you want to get the name of a value's type, you can do it like this:

typeOf("foo").name === "JSString";

See also