DEV Community

loading...

Discussion on: TypeError: JavaScript

Collapse
jreina profile image
Johnny Reina

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.

Collapse
saifsadiq1995 profile image
Saif Sadiq Author

Hi Johnny, I got your point. It was my bad.

Collapse
jonrandy profile image
Jon Randy

What he said 👆

Collapse
vyzaldysanchez profile image
Vyzaldy Andrés Sanchez

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.

Collapse
saifsadiq1995 profile image
Saif Sadiq Author

Thanks Vyzaldy for bringing this to me. I'll look into it.