如何检查JavaScript中的空值?

要在JavaScript中检查null值,您需要使用null检查变量值。使用JavaScript严格相等运算符可实现此目的。

示例

您可以尝试运行以下代码来检查变量的值是否为空-

<html>
   <head>
      <title>JavaScript Strict Equality Operator</title>
   </head>
   <body>
      <script>
         var a = 10;
         if(a === null) {
            document.write("Value is null");
         } else {
            document.write("Value is not null");
         }
      </script>
   </body>
</html>