Tumu Dinakar Tumu Dinakar - 1 year ago 115
Javascript Question

how to create JQuery custom functions with Parameters

Hi I have question that how to create custom functions in jQuery

I have a difficult situation here,

var value1= [];
var value2= [];
var value3= [];

function functionName(first,second,three,four = []) {

$(".btn").click(function(e) {
// 1 st way
// 2nd way


Can i use like this ?
I mean my function 'functionName' has 4 parameters but some cases it has only 3 parameter so in that case I want last parameter should consider as empty.

so I can use like this in JQuery ?

I am using Codeception Test cases but if I use four = [] its getting fail.

Answer Source

Yes you can do this . It is much to do with javascript rather than jQuery

check this snippet

function multiply(a, b = 1) {
  return a*b;


Hope this helps

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download