0
let a = 1;
a.toString()

When a.toString(), a is auto boxing, will become a Number(1), after a.toString(), will a be unboxing or not?

CodeAlien
  • 766
  • 2
  • 7
  • 15

1 Answers1

-1

toString() returns the variable as a string, but does not modify what was originally stored. typeof a after calling toString() returns "number", as it should.

If you wish for a to remain a string after calling toString() on it, you can re-assign it as such: a = a.toString();

Showing typeof a

Gear Folf
  • 24
  • 5
  • I think you don't quite understand what they're asking. `autoboxing` is a behind the scenes process in which a number primitive is swapped out for a Number object. Primitives have no properties, meaning `.toString` doesn't exist, and yet you can call `.toString` just fine because when you do the primitive will be automatically replaced with an object. This is invisible to the developer. https://en.wikipedia.org/wiki/Object_type_(object-oriented_programming)#Autoboxing – Nicholas Tower Oct 23 '20 at 03:22