Possible duplicate:
A question on this JavaScript syntax ("What should I do?")
in this article I found this:
/xyz/.test(function(){xyz;})
I looked at this, and I could not understand how xyz conveyed the call. so I did some similar tests in the console:
/xyz/.test(function(){xya;}) > false /xyz/.test(function(){xyz;}) > true /xyz/.test(function(){'xya';}) > false /xyz/.test(function(){'xyz';}) > true /xyz/.test(function(){console.log('xya');}) > false /xyz/.test(function(){console.log('xyz');}) > true /xyz/.test(function(xya){}) > false /xyz/.test(function(xyz){}) > true /fuc/.test(function(){}) > false /func/.test(function(){}) > true
it seems that the .test() function converts the argument to a string and then performs a test. therefore why is /xyz/.test(function(){xyz;}) used instead of /xyz/.test('xyz') ?
javascript
Gergely Fehérvári
source share