Hey guys, I could really use some help here or maybe an explanation. But shouldn’t my typeof name be number since I changed it to 1 since I changed it? I followed Mosh step by step but I keep getting a different outcome. I’d really appreciate any help.
It is probably still a string.
name here is a property with a getter/setter, and maybe when you set
name to a number, it is
toString()ed, so that when you get
name, you get a string.
avoid using variable names like “name”. This is why you are getting an unexpected result here. “name” is deprecated so typeof is not responding as you would expect.
if you changed “name” to “myname”, you will get the answer you expected ie number not string.
You can also coerce js into accepting a string as a number using “+”. Example …
cl = (...args) => console.log(...args); let myname = "ImReadyHowBoutYou"; cl("myname", typeof myname); // string myname = 1; cl("myname=1", typeof myname); // number // myname = "0123"; cl("myname='0123'", typeof myname); // string cl("myname='0123'", typeof +myname); // number