Note that with those functions, the operands can be negative too. Returning "undefined" when they are negative is not correct.
eg: even the result (eg: cgd) can be negative.......
PS: 2 and 3 are also prime numbers, your functions says it is not (n % 2 = 0).
In many books this isn't talked about (out of convenience, to avoid discussion, because they deal with lower grade maths, etc...), but the fact remains that it can and that they exist. Hence why you usually see
"the greatest common divered of two positive integers" and not
"greatest common divider of two integers" as the latter also requires the book or paper to explain those...