string是TypeScript的原始数据类型(Primitive data types)
除了string外,原始数据类型还有:boolean,number,null,undefined以及ES6中增加的Symbol。
使用原始数据类型定义变量的方法如下:
let s : string = "hello";
String是构造函数
console.log(typeof String);//输出为function
通过new String可以创建实例对象:
let s = new String("hello");
console.log(typeof s);//输出为object
console.log(s.toString());//输出为'hello'
直接调用函数String可返回数据类型为string的变量
let s = String("hello");
console.log(typeof s);//输出为string
console.log(s.toString());//输出为'hello'
boolean与Boolean,number与Number同理。
null与undefined不具备构造函数