Today I needed to exclude hot products and recently viewed products block from homepage, so I needed to find if the current page is homepage. The first block of code worked on header.phtml template but not in main page template, so I ended up using 2nd option.
If you need to check this on header.phtml template then use this code: