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.
A software engineer, JavaScript/Elixir/Golang enthusiast and software engineering lover. I mostly focus myself in backend development, but I also do some frontend every once in a while.
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.
You can add
1
and'H'
in JS. The1
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 thenum
variable.document.getElementById("demo")
is returningnull
in this case and setting properties onnull
throws aTypeError
.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.