how to know if a webpage has mining code? Until recently I have heard that lot of webpages are infected with the javascript which uses your computer's power to mine bitcoins.

Whats the correct method to identify if the website i am browsing is infected by this?
Typically when you browse to a website that is mining with your computer, you will notice that CPU usage increases dramatically. However, if the mining code is tuned to prevent noticeable CPU usage increases, it will be basically impossible to detect if a website is mining through your browser. The only way to know would be to examine each and every website's source code yourself.

However to avoid this problem, you can just prevent JavaScript from running at all. Using a plugin like NoScript, you can prevent JavaScript from executing when you visit any website which will thus prevent JavaScript miners from using your computer to mine cryptocurrencies. You can then enable JavaScript for specific websites and enable certain scripts for each website so that you know are not mining with your computer while still making websites that use JavaScript usable.