What Is Meant By NaN Function In Javascript With Examples

admin_img Posted By Bajarangi soft , Posted On 15-09-2020

The NAN Property Represents "Not-a-Number" Value. This property indicates that a value is Not a legel number. NaN never compare equal to anything. even itself. Th NaN property is the same as the Number.

NaN in JavaScript with example

First Need to Create Nan function
1. Create a function :

Example (1):

<script type="text/javascript">
    var x = 400;
    var y = 10;
    var z = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
    document.write(x/z);
</script>

<!-output Nan-->

Example (2):
<script type="text/javascript">
    var x = 400;
    var y = 10;
    var z = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
    document.write(x/y);
</script>
<!-output 40-->

 


Complete Code of Nan Function In JAvascript:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <title>PHP string replace function</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
    <div class="text-center">
        <h1>What is NaN in Javascript?</h1>
    </div>
    <br>
    <h4>Examples of NaN in javascript.</h4>
    <div class="well">
        <script type="text/javascript">
            var x = 400;
            var y = 10;
            var z = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            document.write(x/y);
        </script>
    </div>
    <div class="well">
        <script type="text/javascript">
            var x = 400;
            var y = 10;
            var z = "Lorem Ipsum is simply dummy text of the printing and typesetting industry.";
            document.write(x/z);
        </script>
    </div>
    <br>
</div>
</body>
</html>

Related Post