name: duk_to_primitive proto: | void duk_to_primitive(duk_context *ctx, duk_idx_t index, duk_int_t hint); stack: | [ ... val! ... ] -> [ ... ToPrimitive(val)! ] summary: |

Replace the object at index with an Ecmascript ToPrimitive() coerced value. The hint argument affects coercion of an object into a primitive type, and indicates preference for a string (DUK_HINT_STRING), a number (DUK_HINT_NUMBER), or neither (DUK_HINT_NONE). DUK_HINT_NONE causes a preference to a number, unless the input value is a Date instance, in which case a string is preferred (the exact coercion behavior is described in the Ecmascript specification). If index is invalid, throws an error.

Custom type coercion:

example: | duk_to_primitive(ctx, -3, DUK_HINT_NUMBER); tags: - stack introduced: 1.0.0