在 javascript 中有3中强制类型转换: Boolean (value), Number(value), String(value)

<html>
  <head>
    <script type="text/javascript">
    var s = String("hello");
    alert(typeof s); //结果是 string
    var s1 = new String("world");
    alert(typeof s1); //结果是 object
    </script>
  </head>
  <body>
  </body>
</html>

所以有没有 new 是完全不同的。 new 代表用对象的方式定义变量。

 

对于 js 中对于函数中定义的变量来说,加 var表示局部变量;不加 var 表示全局变量。

在js 中所有对象都是从object继承过来的。

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-28
  • 2022-12-23
  • 2021-10-15
  • 2022-12-23
  • 2021-11-12
  • 2021-10-02
相关资源
相似解决方案