Bottom note box.
Know Your Phrase - The Meanings For Common Phrases and Sayings > S-Letter Expressions
Example sentences below!
The origins image for this idiom.
The definition picture for this idiom.
Phrases and Idioms - The Meanings and Origins For Several Common Idioms and Phrases
A baseball term that means a batter is swinging at the ball as hard as possible, hoping
for a home run. This phrase is also used figuratively to mean a person is going 'all out',
or giving something their maximum effort.
This phrase likely originates from the sport of baseball. In baseball, it's possible for a
batter to hit the ball hard enough that it flies outside the outfield, making it impossible for
the defensive team to catch or retrieve the ball. This results in a home run for the batter.

With that in mind, there are fences along the edges of the outfield, so if a batter hits the
ball hard enough, it should fly right past those fences and out of the park, which again, would result in a home run. Thus, a batter that's attempting to 'swing for the fences' is basically trying to hit the ball as hard as he can in order to get a home run.

I can only find the expression in writing starting from the first half of the 20th century, and these early recordings of the saying are all used in the context of baseball. For example, the Sandusky Star Journal newspaper, printed in 1923, writes:

"Now the only thought of every batter is to swing his hardest. The home-run germ has even hit the
pitches. No longer do the batters seek to outguess the opposition, trip up the infield, the one big
thought is swing for the fences."
* Jessica will be swinging for the fences for her upcoming math test, but because she's been busy with work all week, she's worried about if she'll be able to pass.
Note: The origins for most idioms are unclear. Often times, the origins you see listed are plausible theories to how an idiom came to be, but not necessarily so. The quotes you see that contain the phrase are the oldest that I could find, but it's very possible there are older recordings somewhere, so if you know of any, let me know!

Keep in mind, just because you see a saying in a newspaper from 1850 does not mean it originated in that year, or from that newspaper. In all likelihood, if a saying is already being used in a form of media like that, it's probably from an earlier time. The purpose of these old quotes is to show, with proof, how old some phrases go back in history.
Swing for the fences phrase title image.
A baseball player!