//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
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
Don't forget to share this article! Help us spread the word by clicking the share button below.
We appreciate your support and are committed to providing you valuable and informative content.
We are thankful for your never ending support.