Using javascript/jquery is there a way to set a variable to a default value if no value is passed in the function? For example
function someFunction(data1,data2)
{
}
If data1 or data 2 is empty it gives me an undefined value. In php I could do just this:
function somefunction(data1 = '',data2 = '')
{
}
So if no variable is passed or data1 or data 2 it defaults to ''. In JS/Jquery do I have to check if there is a value and set it accordingly?
function someFunction(data1,data2)
{
if(!data1) {
data1 = '';
}
if(!data2) {
data2 = ''
}
}
Just seems alot needs to be done to check if variable is empty or not to give it a default value.