In PHP, I’ve used this:
do_it( $var2 = 'something_cool' );
function do_it( $var1, $var2 ) {
// does something
}
In JavaScript, I’m not quite sure the notation.
do_it( var2 = 'something_cool' ); // This isn't right, I don't think.
function do_it( var1, var2 ) {
// does something
}
I want to define var2 but leave var1 empty. What should my do_it look like for the line in question?
Neither of the two are correct. In PHP
var1will get that value in the function. In JS, if you don’t want to assign something to the first parameter, make itnull.And then inside the function, check if it’s null and perhaps give it a default value if it is. Or just reorder them so you don’t have to. In JS you can pass any number of parameters into a function.