insertBefore() does an appendChild() if you pass null as the second argument, so I think this line would work correctly even without the if statement.