I'm new to JavaScript and I'm learning about recursive functions. Specifically, I'm working on Euclid's algorithm. It all makes sense to me except for the base case on line 2 "if ( ! b) { return a; }. I understand that at some point a % b will be equal to NaN and this is when the recursive call should stop. But what does "if ( ! b)" mean in it's simplest form? I can't wrap my head around this. I appreciate the feedback in advance!
// Euclid's Algorithm
var gcd = function(a, b) {
if (!b) {
return a;
}
return gcd(b, a % b);
};
console.log(gcd(462, 910));