+ 2
Why is this code displaying NaN as output?
6 Antworten
+ 6
function multiply() should not have those parameters. Remove them. The reason for NaN is that you were using the variable a and b in the function scope (those are not from the prompt) . As those variables haven't been initiazed the expression happens like this.
var c = a*b
= undefined*undefined
= null
+ 6
Also, var c = a*b instead of var c = document.write(a*b);
+ 4
Coder What's the advantage of storing the call to document.write in a variable? Doesn't make sense to me 🤔
+ 2
Satya Routray Anna said that because c will store undefined as document.write method returns nothing instead of a*b as you want.
+ 1
Nothing…
And I don't think this is going to work… it'll return undefined😀
edit: What is the use of var c? (after you edited) Scrap it. Coder
0
Anna why ?