OneBite.Dev - Coding blog in a bite size

declare a function with multiple parameter in Javascript

Code snippet on how to declare a function with multiple parameter in Javascript

function add(x, y) {
  return x + y;
}

This code declares a function named “add” that takes two parameters, “x” and “y”, and returns the sum of them. To declare the function, the keyword “function” is used followed by the function name which is “add”, two parameters in the parentheses, then the body of the function inside of curly braces. In the body of the function, the parameters “x” and “y” are added together using the ”+” operator and the result is returned using the “return” keyword. In this example, the function “add” will always return the sum of the two parameters regardless of their type or value.

javascript