If you live in a "right to work" state like California, then this is probably something you've wondered about at least once or twice. Most people working today are classified as "at-will" employees, meaning that the employer or employee may terminate the employment relationship at any time, with or without cause.
That means that your boss can fire you for no reason at all, unfortunately, and you'll be left with no legal recourse. It is some consolation, however, that employees can quit their jobs at any time with no adverse effects; the "two week notice" rule is just a professional courtesy and not a legal requirement.
Most public service jobs, and professions with a strong union presence, are the notable exceptions, requiring a supervisor to have "good cause" before firing a subordinate. At will employees may be terminated for any reason (including none at all) except under the fairly strict prohibitions provided by US Federal Law and specific state laws like the Fair Employment and Housing Act in California.
The Fair Employment and Housing Act, or FEHA, protects from harassment or discrimination (up to and including termination) because of age, race, disability, national origin, sexual orientation, gender, etc— it covers more or less the groups you'd expect it to cover. The problem for employees is that the burden of proof is usually on them to provide evidence that the firing was motivated by one of those protected attributes.
Evidence can include co-worker testimony; malicious e-mails, text messages, or voice mail; any kind of written, date stamped, or otherwise verifiable evidence is crucial to building a case— the court can't rely on hearsay. The point is to establish a history of action supporting allegations that the firing was motivated by intolerance or dislike of a protected group.
Fortunately there are a few loopholes that help even the playing field between employer and employee. These include implied contracts, written promises, and breaches of good faith. This section of the law seeks to protect employees who have unwritten or ad-hoc agreements with their employer about the terms and duration of their employment.
"Implied contracts" sometimes includes company policies or employee handbooks which clearly dictate a procedure for terminating employees, it may also include assurances or promises of continued employment, and a history of positive performance reviews.
Breaches of good faith and fair dealing are also common exceptions to at-will employment laws. Included under this heading would be things like an intentionally misleading job description, firing someone to avoid paying a bonus or commission, and trying to coerce an employee to leave by always sticking them in a bad shift.
This blog has glossed over a lot for the sake of readability, but I hope it increases your understanding of the law. Wrongful termination cases can be difficult to prove, and the onus is always on the wronged employee to speak up.