WordPress has a few useful options. You can get the homepage ID by using the following:
$frontpage_id = get_option( 'page_on_front' );
or the blog ID by using:
$blog_id = get_option( 'page_for_posts' );
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.