How to detect for Mobile device Programmatically in Magento 2?

In Magento 2 you can detect mobile device by below code snippets.

Sometimes you need to display different data on mobile device specific or hide some data from the Mobile device at that time you have useful below code snippet.