如何在 JavaScript 中将布尔值转换为字符串值?

javascriptweb developmentfront end technology

要在 JavaScript 中将布尔值转换为字符串值,请使用 toString() 方法。此方法根据对象的值返回"true"或"false"字符串。

示例

您可以尝试运行以下代码将布尔值转换为字符串值−

<html>
   <head>
      <title>JavaScript toString() Method</title>
   </head>

   <body>
      <script>
         var flag = new Boolean(true);
         document.write( "flag.toString is : " + flag.toString() );
      </script>
   </body>
</html>

相关文章


有用资源