object as function parameter javascript code example

Example 1: javascript function variable arguments

function foo() {
  for (var i = 0; i < arguments.length; i++) {
    console.log(arguments[i]);
  }
}

foo(1,2,3);
//1
//2
//3

Example 2: parameters types in javascript

/**
 * My function description
 * @param {String} a
 * @param {String} b
 * @param {Number} amount
 * @example
 * // returns "fooBar fooBar"
 * myFunction('foo', 'Bar', 2)
 * @returns {String}
 */
function myFunction(a, b, amount){
  //do stuff
}
//Note that javascript is not a statically typed language and therefore you
//will not recieve any syntax errors for passing in the wrong types.
//The above code works in Visual Studio Code and intellisense.

Example 3: object as a parameter in javascript

var fac = function me(n) {
    if (n > 0) {
        return n * me(n-1);
    } else {
        return 1;
    }
};
console.log(fac(3)); // 6

Example 4: javascript function with input value

<button class="btn btn-primary" onclick="transmit({search: document.getElementById('search_id').value});">
	<span class="glyphicon glyphicon-search"></span>
</button>

Tags:

Misc Example