Javascript String() 函数

String() — 把对象的值转换为字符串

语法:
  1. String( object );
参数说明:

object — JavaScript 对象

返回值:

返回 object 的 String 类型值。

示例:
  1. var obj_1 = new Date(),
  2. obj_2 = 1234567,
  3. obj_3 = "KILLHAPPY",
  4. obj_4 = new Boolean( true ),
  5. obj_5 = new Boolean( false ),
  6. obj_6 = new Boolean( 1 ),
  7. obj_7 = new Boolean( 0 );
  8. console.log( String( obj_1 ) );
  9. console.log( String( obj_2 ) );
  10. console.log( String( obj_3 ) );
  11. console.log( String( obj_4 ) );
  12. console.log( String( obj_5 ) );
  13. console.log( String( obj_6 ) );
  14. console.log( String( obj_7 ) );
结果:
  1. >>>
  2. Mon Jul 08 2013 11:50:45 GMT+0800
  3. 1234567
  4. KILLHAPPY
  5. true
  6. false
  7. true
  8. false