name: duk_is_primitive proto: | duk_bool_t duk_is_primitive(duk_context *ctx, duk_idx_t idx); stack: | [ ... val! ... ] summary: |

Returns 1 if value at idx is a primitive type, as defined in ToPrimitive, otherwise returns 0. If idx is invalid, also returns 0.

Any standard type other than an object is a primitive type. The custom plain pointer type is also considered a primitive type. However, the custom plain buffer type (which behaves like an Uint8Array object in most situations) and lightfunc type (which behaves like a Function object in most situations) are not considered a primitive type. This matches the behavior of duk_to_primitive() which (usually) coerces e.g. a plain buffer to the string [object Uint8Array].

example: | if (duk_is_primitive(ctx, -3)) { /* ... */ } tags: - stack introduced: 1.0.0