Need explain[Solved] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Need explain[Solved]

Why last one print 421 instead of 43 https://code.sololearn.com/WbvApWnmnPr4/?ref=app

16th Mar 2021, 4:02 PM
Vadivelan
4 Answers
+ 5
because window.name is used to store the window name... as a string ^^ so assigning it a number cast it to a string, and a string plus a number result to concatenating string and number casted to string ;)
16th Mar 2021, 4:17 PM
visph
visph - avatar
+ 3
not a bug: name is a property of window, and store its value as a string...
16th Mar 2021, 4:09 PM
visph
visph - avatar
+ 3
you could overide it by redefining the property explicitly: Object.defineProperty(window,'name',{ value: null, writable: true, })
16th Mar 2021, 4:14 PM
visph
visph - avatar
+ 1
visph ok, I guess I'm just too used to Node.js nowadays. Anyways, 42 is being assigned to `name`, then why is it being stored as string?
16th Mar 2021, 4:15 PM
XXX
XXX - avatar