"When you decide that you want to be just brave, it opens up way more possibilities than trying to be perfect ever does."

So says Alexandria Ocasio-Cortez to NowThis at a recent talk with a group of young women of color who are coders.

Ocasio-Cortez has experienced it first hand.

As a child, she put a lot of pressure on herself to be perfect, she told Reshma Saujani, author of the book "Brave, Not Perfect" and founder of Girls Who Code, at the New York City event in February. Both her parents grew up in poverty, and she saw the sacrifices they made to give her a better life — like her mother cleaning people's houses to pay for her daughter's for piano lessons.

"I felt like I had to be this epic person to justify all the sacrifices that my parents made," Ocasio-Cortez told Saujani.

"That perfectionism in me created a lot of anxiety, and every time I got 80 percent, all I could think of is that it was a 20 percent failure. And if I didn't get into the No. 1 school, then that was it, like I had let people down."

Ocasio-Cortez studied international relations and economics at Boston University and graduated cum laude in 2011. But by the time she was 28, Ocasio-Cortez was working as a waitress, cleaning up after customers and pulling double shifts.

"I felt like a total failure," Ocasio-Cortez said.

However, it also made her brave.

"[I]n a way, it took that rock-bottom, a feeling like a total failure, that I was like, 'well, at this point anything that I do is up. And, like, why not?'"

So Ocasio-Cortez ran for Congress. It was a daunting prospect given that her primary opponent was Rep. Joe Crowley, the fourth-ranking House Democrat, who had represented the district for 10 terms.

But being brave "means actually risking something," Ocasio-Cortez told Saujani.

"Brave does mean you may fail...it's not just like, 'oh, I'm going to do this thing that's probably going to succeed. I'm going to do something with a 70 percent chance of success,'" she said. "No, brave means you're going to go in with a 2 percent chance of success. Bravery is the moonshot."

For Ocasio-Cortez, her moonshot paid off. She shocked the establishment, beating Crowley in the primary and winning the house seat at age 29, making her the youngest woman in history to be elected to Congress. And as a person of color, Ocasio-Cortez became the first representative to fully reflect the demographics of the 14th district, which encompasses parts of Bronx and Queens counties.

Ocasio-Cortez still grapples with anxiety when it comes to failure, she told Saujani, but it's something she's starting to grow out of; she's learning to roll with the punches.

Ocasio-Cortez recalled a particularly freeing moment during the New York primary: Someone forwarded her a leaked email from a local community group that she'd asked for an endorsement. The email talked about Ocasio-Cortez and highlighted her past failures.

"Literally, what I saw when that email was forwarded to me was my inner voice," Ocasio-Cortez said. "It was every critical, horrible thing that I was already saying to myself, that I was already battling when I was getting up out of bed. It was the voice — it was me — looking at myself in the mirror, externalized in an email. And that moment was actually really freeing."

"It's your worst fear, especially when you feel impostor syndrome….feeling like someone was going to find you out as like a fraud," she says. "And I read it, and I was like, 'you know what? I don't care anymore. I don't care anymore, because again, I'm at least trying. And they're not.' So, the power is in the person who's trying, regardless of the success."

Don't miss: Alexandria Ocasio-Cortez: When you only see 'white dudes' running the world, you think you need to act like one

Like this story? Subscribe to CNBC Make It on YouTube!