Investors might end up with a severe case of whiplash trying to keep time with the stock market's gyrations. In 2020, it took the S&P 500 just six months to make up all the ground lost during its collapse at the start of the pandemic, and then it quickly went on to set new record highs. From trough to peak, the broad market index has doubled in value in less than 18 months. 

It shows the wisdom of always staying in the market because you never know what will spark a sharp reversal. It also means there's never a bad time to invest -- and always having money available, even small amounts, is a good strategy for everyone.

Hourglass next to coins and bills.

Image source: Getty Images.

A correction will eventually happen. It always does. But so does the recovery phase that more often than not turns into a raging bull market. If you discount the COVID-19-fueled decline two years ago, the stock market has been climbing inexorably higher for some 13 years since the end of the Great Recession.

Tech stocks have been a key reason behind that drive, though the market began turning against the sector late last year. While their values remain elevated from where they were, there are bargains still to be found, and the four following tech stocks are ones that you should buy and hold for the long term.

Smiling person with credit card, laptop, and shopping bags.

Image source: Getty Images.

JD.com

Like the rest of the world, Chinese consumers have embraced online shopping, and JD.com (JD 5.80%) is increasingly where they're turning to shop. Active customers hit 552.2 million last year, up 25% from 2020, helping to drive third-quarter revenue to $33.9 billion, also a 25% year-over-year gain.

Part of the reason for its success is that unlike rival Alibaba (BABA 2.33%), JD.com is more of a marketplace for third-party sellers than a seller of goods itself, making it more akin to eBay (EBAY 1.09%).

Over the past year or so, however, China has become a risky place to invest as Beijing cracks down on tech companies and those it deems have become too successful. JD.com has so far escaped the scrutiny that's fallen on Alibaba and others, and maintains it will continue to do so. So for investors who understand the risk involved should the government turn its sights on the e-commerce platform, JD.com is a tech stock that should offer generous returns for years to come.

Computer chip with car symbol.

Image source: Getty Images.

Cohu

For many investors, this stock might just as well be Co-who?, but Cohu (COHU 1.01%) is a fast-growing supplier of specialized testing and handling equipment for the world's largest semiconductor manufacturers. It's also positioned to capture the biggest trends in the industry because of its exposure to the automotive industry, more devices tapping into the Internet of Things, and the rollout of 5G networks.

Semiconductor demand is at record levels in the auto industry alone as the global chip shortage has affected the production of vehicles all around the world. Cohu continues to add new auto manufacturers as customers, and two of them account for over 20% of Cohu's revenue. That does represent some concentration risk in the equation should one or both of them move their business elsewhere, but with the market screaming for computer chips, there is a wide runway for Cohu to grow for many years.

At just 10 times trailing earnings and 11 times next year's estimates, some of the lowest valuations in the sector, Cohu is a tech growth stock that should grow and outperform for investors.

Smiling person with a smartphone.

Image source: Getty Images.

AT&T

Now just might be the best time to buy AT&T (T -1.21%). Earlier this month Ma Bell revealed its plan for the spinoff of its Warner Media division and the effect it would have on its dividend payment. The market sent its stock careening lower, and now the telecom giant trades at nine times trailing earnings and seven times estimates, making its stock very cheap.

Ever since AT&T said it would be doing the spinoff (which the market cheered) and cutting the payout (which was booed), its stock has been falling. Shares are now 27% below the highs they were at last May.

Yet the proceeds from the spinoff will allow AT&T to pay down a good chunk of its debt while focusing future capital expenditures on its core telecom business, which is now in growth mode. The rollout of 5G is going to power a lot more than computer chips for smartphone sales, and AT&T has a leading position in the space, even ahead of rival Verizon (VZ -4.67%).

And while AT&T has always been a dependable dividend payer with a payout that currently yields 8.5% annually, even with the coming 50% haircut it's still going to be a top dividend stock on the other side. Wall Street also expects the new $1.11 per share payout to grow again and exceed its current level by 2026. 

With a business arguably better positioned than it has been in years and a still-hefty dividend payment, AT&T is a set-and-forget stock for your portfolio.

Person plugging extension cord into car.

Image source: Tesla.

Tesla

Unlike most of these other tech stocks to add to the long-term portion of your portfolio, Tesla's (TSLA -3.40%) stock is not cheap by traditional metrics. The electric car maker trades at more than 900 times earnings(!), 17 times sales, and 100 times the free cash flow it produces. While shares traded north of $1,200 each not too long ago, they're down 25% since.

Yet Tesla is only just hitting its stride, selling almost 1 million vehicles last year, or about half of what the biggest old line manufacturers produced. So in just over 10 years, it has surpassed some of the biggest names in the industry in terms of production, and with new gigafactories regularly coming online, CEO Elon Musk just might hit his goal of 20 million EVs by 2030.

Tesla is now also consistently profitable, something other EV makers can't say. Though some analysts say the share price should be closer to $150 than $1,000, Tesla has more growth to come.