MDN wants to talk to developers like you:


Obsolete since JSAPI 32
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

Cast a boolean JavaScript value to a C integer, either 0 or 1, without any type checking or error handling.




JSVAL_TO_BOOLEAN casts the value v to a C integer, either 0 or 1. As a precondition, JSVAL_IS_BOOLEAN(v) must be true. That is, v must be either JSVAL_TRUE or JSVAL_FALSE. Otherwise the behavior is undefined.

The result is JS_TRUE or JS_FALSE respectively. These are constants of type JSBool, which is an integer type, the SpiderMonkey version of bool. JS_FALSE is 0; JS_TRUE is 1.

To convert any value to a boolean, use JS_ValueToBoolean instead. That function has well-defined behavior even when the argument is an object, number, or something else.

To convert a JSBool to jsval, use BOOLEAN_TO_JSVAL.

See Also

Document Tags and Contributors

 Contributors to this page: arai, fscholz, Jorend, Dria, Nickolay, Callek
 Last updated by: arai,