In both ActionScript3 and Javascript, these statements give the same result:
/\S/.test(null) => true /null/.test(null) => true /m/.test(null) => false /n/.test(null) => true
It seems that in this case, a null value is converted to the string "null".
Is this a known bug in ecmascript or am I missing something?
This is not a mistake, but you are right, nullcoerces to 'null'and this behavior is defined in the specification:
null
'null'
RegExp.prototype.test(string)
RegExp.prototype.exec(string) != null
exec
ToString
"null"
, , RegExp 'null', , 'n'.
'n'
var a = null+''; // 'null' /\S/.test(a); // true (null+'').match(/\S/) // ["n"]
null - object, objects (non-string) , .
/Number/.test(Number) /String/.test(String), true.
/Number/.test(Number)
/String/.test(String)
true
String(null), 'null'
String(null)
String(Number)
function Number() { [native code] }
/function Number/.test(Number) true
/function Number/.test(Number)