I just came across the following code:
function showMatch(str, reg) {
var res = [], matches
while(true) {
matches = reg.exec(str)
if (matches === null) break
res.push(matches[0])
if (!reg.global) break
alert(res)
}
Can anybody please explain the second row? Does
var res = [], matches
equal
var res=[]; res=matches
or
var res=[]; var matches=[]
?
I guess the second answer is correct? I find this little confusing...
It equivalent to
var res = [];
var matches;
where matches
is undefined
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With