write a simple js code to add two numbers
Certainly! Here's a simple JavaScript code snippet that adds two numbers:
function addNumbers(num1, num2) { return num1 + num2; } // Example usage: const result = addNumbers(5, 3); console.log(result); // Output: 8
In this code, we define a function addNumbers
that takes two parameters num1
and num2
. Inside the function, we simply add the two numbers together using the +
operator and return the result.
To use this function, you can call it with the two numbers you want to add as arguments. In the example usage, we call addNumbers
with the numbers 5 and 3, and the result is stored in the result
variable. Finally, we print the result to the console using console.log
.
Please let me know if you need any further assistance!