(ES6) ES6 (2016)

Coersion (CR29)

   1:  const num = 42;
   2:  const str = String(num);        // Number to string
   3:  const bool = true;
   4:  const nul = null;
   5:  const und = undefined;
   6:  const special = NaN;
   7:  const big = 1234567890123456789n;
   8:  
   9:  const boolFromNum = Boolean(num);   // Number to boolean (0 is falsy, others truthy)
  10:  const boolFromStr = Boolean(str);   // String to boolean (empty string "" is falsy, others truthy)
  11:  const boolFromBig = Boolean(big);   // BigInt to boolean (0n is falsy, others truthy).
  12:  const boolFromNul = Boolean(nul);   // Null to boolean (falsy)
  13:  const boolFromUnd = Boolean(und); // Undefined to boolean (falsy)
  14:  const boolFromNan = Boolean(special); // NaN to boolean (falsy)
  15:  
  16:  console.log(boolFromNum);
  17:  console.log(boolFromStr);
  18:  console.log(boolFromBig);
  19:  console.log(boolFromNul);
  20:  console.log(boolFromUnd);
  21:  console.log(boolFromNan);



Boolean Conversions:

true
true
true
false
false
false





Coersion context:






ES6 context:



Comments ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23>  <24>  <25
Link to this page: http://www.vb-net.com/JavascriptES6/CR29.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>