Add two variables using jquery - javascript


In jQuery, you can sum two variables using the `+` operator, just like you would in regular JavaScript. Here's an example:

Add two variables using jquery - javascript




      <!DOCTYPE html>
      <html lang="en">
      <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Sum Two Variables in jQuery</title>
        <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
      </head>
      <body>

      <script>
        $(document).ready(function() {
          // Define two variables
          var variable1 = 10;
          var variable2 = 20;

          // Sum the two variables
          var sum = variable1 + variable2;

          // Display the result
          console.log("Sum: " + sum);
        });
      </script>

      </body>
      </html>


In this example, `variable1` and `variable2` are two variables with numeric values. The sum of these variables is calculated using the `+` operator, and the result is stored in the `sum` variable. Finally, the result is displayed in the console using `console.log()`.


0 Comments