I have been going through nodeschool's regex-adventure and I have just completed the captures lesson.
My solution:
module.exports = function (str) {
var x = /x=(\d+)/.exec(str);
return x && x[1];
}
However the reference solution has
module.exports = function (str) {
var x = /x=(\d+)/.exec(str);
return x ? x[1] : null;
}
I am really just curious as to what the last line means.
x
zero or one time x[1]
but I am unaware of what : null;
means in this instance. Does it mean "if not null"?