//method 1 var str = "Display sum of two digit = "; var str = str + 2 + 2; alert(str); //method 2 var z = 2 + 2 ; alert(z);
Method 1 :
Display sum of two digit = 22
Method 2 :
Here in method 2 we add two number and alert the output and output display as :
Method 2 display the desirable ouput but what with the first method when we try to display number with string using concatenate method . There is a solution we easily can add these number using brackets . This method first add these two values and concatenated to string.
var str = "Display sum of two digit = "; var str = str + (2 + 2); alert(str); //output : Display sum of two digit = 4