JavaScript 中如何将 -Infinity 转换为布尔值?

htmljavascriptprogramming scripts

使用 JavaScript 中的 Boolean() 方法转换为布尔值。您可以尝试运行以下代码来了解如何在 JavaScript 中将 -Infinity 转换为布尔值。

示例

<!DOCTYPE html>
<html>
   <body>
      <p>Convert -Infinity to Boolean</p>
      <script>
         var myVal = -Infinity;
         document.write("Boolean: " + Boolean(myVal));
      </script>
   </body>
</html>

相关文章