Search notes:

JavaScript: comparing undefined to other values

The following simple HTML document contains a bit of JavaScript that compares undefined to a few values and prints if this comparison is true or false.
<!DOCTYPE html>
<html>
<head>
  <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
  <title>undefined</title>

  <script type="text/javascript">

    var out;

    function evalAndPrint(expr) {

      var res = eval(expr);

      expr.replace(/&/g, '&amp;');
      expr.replace(/</g, '&lt;' );
      expr.replace(/g/g, '&gt;' );


      if (res) { out.innerHTML += expr + " is true<br>";  } else
               { out.innerHTML += expr + " is false<br>"; }

    }

    function main() {

      out = document.getElementById('out');

      evalAndPrint('5         ==  undefined'); // false
      evalAndPrint('5         !=  undefined'); // true
      evalAndPrint('5         >   undefined'); // false
      evalAndPrint('undefined >   undefined'); // false
      evalAndPrint('undefined ==  undefined'); // true
      evalAndPrint('undefined === undefined'); // true
      evalAndPrint('NaN       === undefined'); // true

    }

  </script>

</head>
<body onload='main()';>
  <div id='out'>
  </div>
</body>
</html>
Github repository about-javascript, path: /objects/Global-Object/value-properties/undefined/compare.html

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758204813, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/JavaScript/objects/global/value-properties/undefined/compare(81): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78