Exception Handling in JavaScript

Below is the simple code to understand, how to handle the exception using javascript and alert to user.

<script language="javascript" type="text/javascript">
        window.onload = intAll;
        function intAll(){
            var ans = window.prompt("Enter a number","");
                if (isNaN(ans) || ans < 0)
                    throw new Error("Invalid Number");
                    alert("Square root of the number " + ans + " is " + Math.sqrt(ans));
            catch (err){


How to check JavaScript disable in browser?

It is very easy to detect whether JavaScript is disable on browser or not?

You just need to put <noscript> tag in your HTML body. For example,

<div>Javascript is disable on your browser</div>

If JavaScript is disable then above HTML text will be print on html document.