To add two numbers in JavaScript, first declare two variables and assign values to them. Then use the + (plus) operator to add the variables together. Here's an example:
84 chars5 lines
In this example, we declare two variables num1
and num2
and assign them the values of 5 and 10 respectively. Then we declare a third variable sum
and set it equal to the sum of num1
and num2
. Finally, we log the value of sum
to the console, which outputs 15.
gistlibby LogSnag