I know that JavaScript support Autoboxing (the automatic conversion from a primitive data type to its object counterpart), but does JavaScript also support Unboxing (the automatic conversion from an object to its primitive data type counterpart)?
but does JavaScript also support Unboxing (the automatic conversion from an object to its primitive data type counterpart)
Yes it does. This is quite what happens for example when you do:
'' + { };
Which gets you:
'[object Object]'
Although this doesn't exactly fit "Unboxing".
I think a better example would be to use either a String or a Number. Since those are the values that actually get boxed.
new String('test') + '!!!' // "test!!!"
2 ** (new Number(2)) // 4
2 + (new Number(2)) //4
2 / (new Number(2)) //1
The easiest way to obtain the underlying primitive value from an object wrapper is to use the valueOf() method:
const a = Object(false);
a == false; //true
a === false //false
a.valueOf() == false //true
a.valueOf() === false //true