在 JavaScript 中将 1 转换为布尔值会发生什么?

htmljavascriptprogramming scripts

您可以尝试运行以下代码来了解如何在 JavaScript 中将 1 转换为布尔值 −

示例

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

相关文章