The stock market has experienced unprecedented growth over the past year, but that may not last much longer.

It's uncertain when a stock market crash will hit, but one thing is for sure: It will strike eventually. The upward trajectory the market has seen since last spring can't last forever, so it's only a matter of time before we're in another downturn.

When, exactly, that will happen is anyone's guess. But if a crash is looming, should you still be investing in the stock market right now? Here's what you need to know.

Young person sitting at a desk looking at a laptop.

Image source: Getty Images.

The advantage of investing when the market is shaky

It can be nerve-wracking to invest when the stock market is volatile or on the verge of a crash. After all, nobody wants to invest their hard-earned savings only to see their portfolio plummet in value shortly after.

However, investing during a downturn can be a financially smart decision for a couple of reasons.

For one, stock prices are lower when the market is in a slump. This means you have a fantastic opportunity to buy stocks you've had your eye on while they're essentially on sale. The more severe the market crash, the deeper the discounts on your favorite stocks. By investing during a downturn, you could potentially save a lot of money when strengthening your portfolio.

Another advantage of buying when prices are lower is that you can take advantage of dollar-cost averaging. With this strategy, you're buying stocks at regular intervals throughout the year. Sometimes, you'll end up investing when stock prices are high. Other times, prices will be lower.

Over time, those highs and lows should average out. But if you stop investing during downturns, you're only buying when prices are at their highest, which could cost you over the long run.

The dangers of trying to time the market

It's also important to keep in mind that if you press pause on investing before a downturn -- or pull your money out of the market altogether -- you're essentially trying to time the market.

When you time the market, you're trying to sell when stock prices are at their highest, then buy again once prices are at rock bottom. In theory, this sounds like a smart strategy. However, it can be extremely difficult to pull off successfully.

Nobody can predict how the stock market will perform, especially when it comes to when, exactly, a crash will occur. If you sell your stocks now thinking the market will crash tomorrow, there's a good chance prices may continue rising -- and you'll have missed out on those gains.

On the other hand, if you wait until the market is already crashing to sell, you might end up selling your stocks after prices have plummeted, locking in your losses. In other words, unless you get extremely lucky and pull out of the market at just the right moment, you're likely to lose money.

A better option, then, is to simply hold your stocks and continue investing regularly regardless of what the market does. As long as you're buying solid stocks that have a good chance of rebounding after a crash, holding your investments is the best way to survive market volatility.