McGinley told Hollywood.com that Scrubs fans loved the abrasive Dr Cox so much because he was deeply troubled.
"What helps writers, and ultimately, obviously, helps the actors - who should serve the words that the writer puts on the page - is if the character has damages," the actor explained. "Because then the writers can cultivate and excavate, like a dentist going into a tooth.
"You go into those damages and write interesting stories for a prolonged period of time. So, Cox is so damaged that they got to write him for nine years, and he never became an exercise in redundancy."
McGinley also revealed that one of the challenges of playing Dr Cox was accurately portraying the physician's intellect.
"I surrendered to this early on: Dr. Cox, SAT- and IQ-wise, runs circles around me," he quipped. "That's a horrible thing to say about yourself. I think the guy is super, super bright. And probably rebels against that, and tries to damage his intellect with booze."
Scrubs star Zach Braff admitted last year that he misses the cast's camaraderie.
"It was the best job in the world, because you essentially went to work every day and laughed and acted like a goofball with all of your friends. A job doesn't get better than that," Braff recalled.
The medical-themed sitcom aired for nine seasons in all, earning two Emmy Awards and three Golden Globe nominations.
Watch clips from Scrubs below: