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).
posted @ 2019-04-24 01:04  zllmh  阅读(89)  评论(0编辑  收藏  举报