You can add 1 and 'H' in JS. The 1 gets coerced to a string and the result is '1H'.
Also, the Cannot set property 'innerHTML' of null error has nothing to do with the type of the num variable. document.getElementById("demo") is returning null in this case and setting properties on null throws a TypeError.
Cannot set property 'innerHTML' of null
Hi Johnny, I got your point. It was my bad.
What he said 👆
Yes, you're right.adding a number with an integer will result in JS triggering implicit coercion which will convert the number into string and it will perform concatenation instead. No errors thrown.
Thanks Vyzaldy for bringing this to me. I'll look into it.
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.