Can I mine cryptocurrency using Javascript? Is it a good idea to mine a Scrypt-based cryptocurrency, like Dogecoin or Digitalcoin, using Javascript instead of having paid ads.

The script would mine using all computers visiting my website.
I see where you are coming from and I wouldn't be surprised on some systems if the user has less of a bad experience than ads (some sites filled with ads are simply unbrowseable for some). 

But, Javascript is not a quick language and you wont generate any coins worth generating, no pool will allow you to direct this sort of traffic to them in any significant quantity and if you run your own p2pool the bandwidth and other resources will far outweigh the coins mined. 

As a rough but educated guess that you'll probably generate about 1-2kh/s per user while they are on your site, meaning you'd need 250,000-300,000 simultaneous viewers to match a modern scrypt mining rig, take into account overheads and you're probably looking at more like 400-500,000 viewers. 

In other words, don't do it. Your users will hate the site, it will lag video and audio and generally create a poor browsing experience meaning users won't stay on your site meaning you wont get the required hundreds of thousands of viewers. You may also get flagged for malware by Google etc. and like I say, pools wont accept it.