Symbol Coercion

  • explicit coercion of a symbol to a string is allowed, but implicit coercion of the same is disallowed and throws an error.
var s1 = Symbol( "cool" );
String( s1 );                   // "Symbol(cool)"

var s2 = Symbol( "not cool" );
s2 + "";                        // TypeError
  • symbol values cannot coerce to number at all (throws an error either way), but strangely they can both explicitly and implicitly coerce to boolean (always true).

猜你喜欢

转载自www.cnblogs.com/zlv2snote/p/10760146.html