Product is one of the most important factors of the online store, so we have to take care of all these functionalities. In Magento 2 there is one functionality about the Out of Stock Product configuration. Store owners can choose what they want to show and what they don't what to show for the customer.
How to Show Out of Stock Product in Magento 2
in order to change the setting of stock inventory you have to open the Magento 2 admin panel and then change the
Stores > Configuration > Catalog > Inventory > Stock Options > Display Out of Stocks > Yes
And choose to display out-of-stock products as a Yes if you don't want to show them then choose No to not show on the frontend in Magento 2.
Don't Show Out Of Stock Products
If you will select No then the product will not display on the frontend and Magento 2 by default setting has No.
Stores > Configuration > Catalog > Inventory > Stock Options > Display Out of Stocks > No