Parameter is seen as string Javascript
16:09 09 Jul 2020

I just started using Javascript and I have a small beginner question.

I have created 2 functions, only when I place an argument for a function my 2 parameters are seen as a string and they are not added properly.

par1 = 5 , par2 = 2

function sum(par1,par2){
    
    return document.write("Sum : " + par1+par2 + "
"); } function multi(par1,par2){ return document.write(" Multi : "+par1*par2); }

If I remove the "Sum:" + function from the sum function, it adds up well, but if I leave it in, my parameters are seen as string and I get result 52 instead of 7.

In multi function it just works well.

Thank you in advance for answering my question!

javascript