+ sign to add numbers.
Run the above example:
Here we have defined two variables with static integer values. Then calculate the sum of both values and store them in a third variable. Finally, the result is displayed on the console.
Another Example with User Input
Let’s consider another example to calculate the sum of values based on user input. First, have a look at the below program.
See the result of the above example:
This program takes input from user. Here the window.prompt() function create a popuop box in browser to accept input. This input is in string format. So next, we use parseint() function to convert a string value to a integer.
Finally, calculate the sum of both integers and print the results. This time the results will be shown in a popup box.