How to get a customer is logged in or not in Magento 2

Add the following code in phtml file: How to get customer is logged-in or not in Magento 2 How to get customer is logged-in or not in Magento 2expoundsofttechsolution How to get customer is logged-in or not in Magento 2
        <?php  
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$customerSession = $objectManager->get('Magento\Customer\Model\Session');
if(!$customerSession->isLoggedIn()) {
echo "Customer not logged-in";
}
else{
echo "Customer logged-in";
}
    ?>