This article is in need of a technical review.

This article covers features introduced in SpiderMonkey 1.8.1

Determines if two jsvals are the same, as determined by the SameValue algorithm in ECMAScript 262, 5th edition. SameValue slightly differs from strict equality (===) in that +0 and -0 are not the same and in that NaN is the same as NaN. The SameValue algorithm is equivalent to the following JavaScript:

function SameValue(v1, v2)
  if (v1 === 0 && v2 === 0)
    return 1 / v1 === 1 / v2;
  if (v1 !== v1 && v2 !== v2)
    return true;
  return v1 === v2;


JSBool JS_SameValue(JSContext *cx, jsval v1, jsval v2);
Name Type Description
cx JSContext * Pointer to a JS context from which to derive runtime information. Requires request. In a JS_THREADSAFE build, the caller must be in a request on this JSContext.
v1 jsval The first value.
v2 jsval The second value.


JS_SameValue determines whether two values are the same, returning JS_TRUE or JS_FALSE accordingly. This method is infallible.

MXR ID Search for JS_SameValue

Document Tags and Contributors

Contributors to this page: kscarfone, ethertank
Last updated by: kscarfone,