Investing in the stock market is one of the best ways to build wealth, but it can be nerve-wracking at times -- especially when the market is volatile.

The market has been on a roller-coaster so far this year, and there's a chance a crash could be on the horizon. There's a lot of uncertainty in the world right now, and sometimes, uncertainty results in greater volatility in the market.

To be clear, nobody knows when or if a crash will happen. But I'm doing a few things to prepare just in case.

Person standing inside looking out a window.

Image source: Getty Images.

1. I'm continuing to invest

Market crashes can be intimidating, but they can also be fantastic buying opportunities. Stock prices are lower during downturns, which means you can load up on quality investments for a fraction of the cost.

Regardless of what happens with the market, I'm going to continue investing like normal. If stock prices fall, I'll take that opportunity to invest at a discount. Strong investments are likely to recover from even the worst downturns, so when prices inevitably rebound, you'll reap the rewards.

2. I'm only investing money I won't need soon

While market downturns can be a great chance to buy, it's important to make sure you're not investing more than you can afford.

Crashes are one of the worst opportunities to withdraw your investments because stock prices are at their lowest. If you invest all your money in the stock market, prices fall, and then you realize you need that cash, you risk selling your investments for far less than you paid for them.

Before I invest anything, I double-check that my emergency fund is robust enough to cover any unexpected expenses. I also only invest money I won't need for the foreseeable future so that I won't have to worry about withdrawing my savings during a downturn.

3. I'm double-checking my portfolio

The investments in your portfolio can make or break your strategy, as not all stocks can survive market volatility. Now is the perfect opportunity, then, to double-check that your portfolio is diversified and filled with strong investments.

Ideally, you should be investing in at least 25 to 30 stocks across multiple industries. Or you may opt to invest in mutual funds or exchange-traded funds (ETFs) that offer built-in diversification by including a wide variety of stocks.

Regardless of whether you invest in individual stocks or funds, make sure every investment deserves a spot in your portfolio. If you own many stocks with shaky fundamentals, your portfolio may have a harder time surviving a downturn.

4. I'm keeping a long-term outlook

The stock market is unpredictable in the short term, but it has consistently earned positive average returns over the long run. For that reason, I don't worry too much about how the market will perform in the coming weeks or months. Rather, I try to stay focused on its performance over decades.

^SPX Chart

^SPX data by YCharts.

Even the worst market crashes are only temporary. As long as you're investing in the right places, there's a good chance your portfolio will recover eventually. In the meantime, try your best to avoid getting hung up on the market's daily fluctuations and focus instead on its long-term performance.

It's uncertain what the future holds for the stock market, but that doesn't mean you can't be prepared. With the right strategy, you can rest easier knowing you'll be ready for whatever may happen.